From b5a887aa5e554ec3f6a3a770f82d82494ee0e95e Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 23 Oct 2018 09:58:24 +0100 Subject: [PATCH] Fix nxos_ospf_vrf module auto-cost idempotency and module check mode (#47190) * fixing idempotency and check mode * modified to avoid repetitive code (cherry picked from commit dcb35c427092b3bc2ef8f9b9e1132a3184b9e20b) --- changelogs/fragments/nxos_ospf_vrf_idempotence.yaml | 2 ++ lib/ansible/modules/network/nxos/nxos_ospf_vrf.py | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/nxos_ospf_vrf_idempotence.yaml diff --git a/changelogs/fragments/nxos_ospf_vrf_idempotence.yaml b/changelogs/fragments/nxos_ospf_vrf_idempotence.yaml new file mode 100644 index 00000000000..930a3ff73a6 --- /dev/null +++ b/changelogs/fragments/nxos_ospf_vrf_idempotence.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix nxos_ospf_vrf module auto-cost idempotency and module check mode (https://github.com/ansible/ansible/pull/47190). diff --git a/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py b/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py index 8e74de67e73..fbc9e752d60 100644 --- a/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py +++ b/lib/ansible/modules/network/nxos/nxos_ospf_vrf.py @@ -204,7 +204,7 @@ def get_existing(module, args): elif 'auto' in line: cost = re.search(r'auto-cost reference-bandwidth (\d+) (\S+)', line).group(1) if 'Gbps' in line: - cost *= 1000 + cost = int(cost) * 1000 existing['auto_cost'] = str(cost) elif 'timers throttle lsa' in line: tmp = re.search(r'timers throttle lsa (\S+) (\S+) (\S+)', line) @@ -377,7 +377,7 @@ def main(): warnings = list() check_args(module, warnings) - result = dict(changed=False, warnings=warnings) + result = dict(changed=False, commands=[], warnings=warnings) state = module.params['state'] args = PARAM_TO_COMMAND_KEYMAP.keys() @@ -407,12 +407,10 @@ def main(): if candidate: candidate = candidate.items_text() - load_config(module, candidate) - result['changed'] = True result['commands'] = candidate - - else: - result['commands'] = [] + if not module.check_mode: + load_config(module, candidate) + result['changed'] = True module.exit_json(**result)