From cff4a2d26e8720114475345fee7f944751bb0016 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Thu, 25 Jan 2018 18:49:20 +0530 Subject: [PATCH] fix *os_config module backward diff (#35332) Signed-off-by: Trishna Guha --- lib/ansible/modules/network/eos/eos_config.py | 9 ++++++++- lib/ansible/modules/network/ios/ios_config.py | 9 ++++++++- lib/ansible/modules/network/nxos/nxos_config.py | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/network/eos/eos_config.py b/lib/ansible/modules/network/eos/eos_config.py index 574c89d3137..fbb765fd003 100644 --- a/lib/ansible/modules/network/eos/eos_config.py +++ b/lib/ansible/modules/network/eos/eos_config.py @@ -458,9 +458,16 @@ def main(): base_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) if running_config.sha1 != base_config.sha1: + if module.params['diff_against'] == 'intended': + before = running_config + after = base_config + elif module.params['diff_against'] in ('startup', 'running'): + before = base_config + after = running_config + result.update({ 'changed': True, - 'diff': {'before': str(base_config), 'after': str(running_config)} + 'diff': {'before': str(before), 'after': str(after)} }) module.exit_json(**result) diff --git a/lib/ansible/modules/network/ios/ios_config.py b/lib/ansible/modules/network/ios/ios_config.py index e37e5c88abc..8c367909f0b 100644 --- a/lib/ansible/modules/network/ios/ios_config.py +++ b/lib/ansible/modules/network/ios/ios_config.py @@ -532,9 +532,16 @@ def main(): base_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) if running_config.sha1 != base_config.sha1: + if module.params['diff_against'] == 'intended': + before = running_config + after = base_config + elif module.params['diff_against'] in ('startup', 'running'): + before = base_config + after = running_config + result.update({ 'changed': True, - 'diff': {'before': str(base_config), 'after': str(running_config)} + 'diff': {'before': str(before), 'after': str(after)} }) module.exit_json(**result) diff --git a/lib/ansible/modules/network/nxos/nxos_config.py b/lib/ansible/modules/network/nxos/nxos_config.py index 02374043ca3..d1b7b90046c 100644 --- a/lib/ansible/modules/network/nxos/nxos_config.py +++ b/lib/ansible/modules/network/nxos/nxos_config.py @@ -493,9 +493,16 @@ def main(): base_config = NetworkConfig(indent=1, contents=contents, ignore_lines=diff_ignore_lines) if running_config.sha1 != base_config.sha1: + if module.params['diff_against'] == 'intended': + before = running_config + after = base_config + elif module.params['diff_against'] in ('startup', 'running'): + before = base_config + after = running_config + result.update({ 'changed': True, - 'diff': {'before': str(base_config), 'after': str(running_config)} + 'diff': {'before': str(before), 'after': str(after)} }) module.exit_json(**result)