Browse code

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)

Dan authored on 2018/10/23 17:58:24
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+- Fix nxos_ospf_vrf module auto-cost idempotency and module check mode (https://github.com/ansible/ansible/pull/47190).
... ...
@@ -204,7 +204,7 @@ def get_existing(module, args):
204 204
             elif 'auto' in line:
205 205
                 cost = re.search(r'auto-cost reference-bandwidth (\d+) (\S+)', line).group(1)
206 206
                 if 'Gbps' in line:
207
-                    cost *= 1000
207
+                    cost = int(cost) * 1000
208 208
                 existing['auto_cost'] = str(cost)
209 209
             elif 'timers throttle lsa' in line:
210 210
                 tmp = re.search(r'timers throttle lsa (\S+) (\S+) (\S+)', line)
... ...
@@ -377,7 +377,7 @@ def main():
377 377
 
378 378
     warnings = list()
379 379
     check_args(module, warnings)
380
-    result = dict(changed=False, warnings=warnings)
380
+    result = dict(changed=False, commands=[], warnings=warnings)
381 381
 
382 382
     state = module.params['state']
383 383
     args = PARAM_TO_COMMAND_KEYMAP.keys()
... ...
@@ -407,12 +407,10 @@ def main():
407 407
 
408 408
     if candidate:
409 409
         candidate = candidate.items_text()
410
-        load_config(module, candidate)
411
-        result['changed'] = True
412 410
         result['commands'] = candidate
413
-
414
-    else:
415
-        result['commands'] = []
411
+        if not module.check_mode:
412
+            load_config(module, candidate)
413
+            result['changed'] = True
416 414
     module.exit_json(**result)
417 415
 
418 416