diff --git a/lib/ansible/modules/network/nxos/nxos_overlay_global.py b/lib/ansible/modules/network/nxos/nxos_overlay_global.py index c47ddce4f8..5ed4548ac0 100644 --- a/lib/ansible/modules/network/nxos/nxos_overlay_global.py +++ b/lib/ansible/modules/network/nxos/nxos_overlay_global.py @@ -72,11 +72,12 @@ def get_existing(module, args): for arg in args: command = PARAM_TO_COMMAND_KEYMAP[arg] - has_command = re.match(r'(?:{0}\s)(?P.*)$'.format(command), config, re.M) + has_command = re.findall(r'(?:{0}\s)(?P.*)$'.format(command), config, re.M) value = '' if has_command: - value = has_command.group('value') + value = has_command[0] existing[arg] = value + return existing @@ -102,8 +103,10 @@ def get_commands(module, existing, proposed, candidate): else: if 'anycast-gateway-mac' in key: value = normalize_mac(value, module) - command = '{0} {1}'.format(key, value) - commands.append(command) + existing_value = existing_commands.get(key) + if existing_value and value != existing_value: + command = '{0} {1}'.format(key, value) + commands.append(command) if commands: candidate.add(commands, parents=[]) diff --git a/test/units/modules/network/nxos/fixtures/nxos_overlay_global_config.cfg b/test/units/modules/network/nxos/fixtures/nxos_overlay_global_config.cfg new file mode 100644 index 0000000000..45a6ff99c7 --- /dev/null +++ b/test/units/modules/network/nxos/fixtures/nxos_overlay_global_config.cfg @@ -0,0 +1 @@ +fabric forwarding anycast-gateway-mac 000B.000B.000B diff --git a/test/units/modules/network/nxos/test_nxos_overlay_global.py b/test/units/modules/network/nxos/test_nxos_overlay_global.py index 3bcc9f8a61..2f05077c09 100644 --- a/test/units/modules/network/nxos/test_nxos_overlay_global.py +++ b/test/units/modules/network/nxos/test_nxos_overlay_global.py @@ -42,9 +42,10 @@ class TestNxosOverlayGlobalModule(TestNxosModule): self.mock_get_config.stop() def load_fixtures(self, commands=None, device=''): + self.get_config.return_value = load_fixture('', 'nxos_overlay_global_config.cfg') self.load_config.return_value = None def test_nxos_overlay_global_up(self): - set_module_args(dict(anycast_gateway_mac="b.b.b")) + set_module_args(dict(anycast_gateway_mac="a.a.a")) result = self.execute_module(changed=True) - self.assertEqual(result['commands'], ['fabric forwarding anycast-gateway-mac 000B.000B.000B']) + self.assertEqual(result['commands'], ['fabric forwarding anycast-gateway-mac 000A.000A.000A'])