From 73f42d22ffd52611876017df59940fb08cf04192 Mon Sep 17 00:00:00 2001 From: Sumit Jaiswal Date: Wed, 13 Nov 2019 00:49:18 +0530 Subject: [PATCH] Backport PR to fix ios_interfaces where non-existing virtual/loopback interfaces was not getting configured (#64259) * fix bug 63761 (#63901) (cherry picked from commit be1bcc745019613c722c73c1562c11215b146dd3) * changelog --- ...s-for-non-existing-virtual-interfaces.yaml | 4 ++++ .../ios/config/interfaces/interfaces.py | 21 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/63901-fix-ios-interfaces-for-non-existing-virtual-interfaces.yaml diff --git a/changelogs/fragments/63901-fix-ios-interfaces-for-non-existing-virtual-interfaces.yaml b/changelogs/fragments/63901-fix-ios-interfaces-for-non-existing-virtual-interfaces.yaml new file mode 100644 index 00000000000..d11c7352d0a --- /dev/null +++ b/changelogs/fragments/63901-fix-ios-interfaces-for-non-existing-virtual-interfaces.yaml @@ -0,0 +1,4 @@ +--- +bugfixes: +- "To fix ios_interfaces where non-existing virtual/loopback interfaces was not getting configured" +- "(https://github.com/ansible/ansible/pull/63901)" diff --git a/lib/ansible/module_utils/network/ios/config/interfaces/interfaces.py b/lib/ansible/module_utils/network/ios/config/interfaces/interfaces.py index c5818104c54..59ac20c2d53 100644 --- a/lib/ansible/module_utils/network/ios/config/interfaces/interfaces.py +++ b/lib/ansible/module_utils/network/ios/config/interfaces/interfaces.py @@ -140,10 +140,11 @@ class Interfaces(ConfigBase): elif interface['name'] in each['name']: break else: + # configuring non-existing interface + commands.extend(self._set_config(interface, dict())) continue have_dict = filter_dict_having_none_value(interface, each) - want = dict() - commands.extend(self._clear_config(want, have_dict)) + commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._set_config(interface, each)) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) @@ -163,10 +164,12 @@ class Interfaces(ConfigBase): for each in have: for interface in want: + count = 0 if each['name'] == interface['name']: break elif interface['name'] in each['name']: break + count += 1 else: # We didn't find a matching desired state, which means we can # pretend we recieved an empty desired state. @@ -174,9 +177,17 @@ class Interfaces(ConfigBase): commands.extend(self._clear_config(interface, each)) continue have_dict = filter_dict_having_none_value(interface, each) - want = dict() - commands.extend(self._clear_config(want, have_dict)) + commands.extend(self._clear_config(dict(), have_dict)) commands.extend(self._set_config(interface, each)) + # as the pre-existing interface are now configured by + # above set_config call, deleting the respective + # interface entry from the want list + del want[count] + + # Iterating through want list which now only have new interfaces to be + # configured + for each in want: + commands.extend(self._set_config(each, dict())) # Remove the duplicate interface call commands = remove_duplicate_interface(commands) @@ -198,6 +209,8 @@ class Interfaces(ConfigBase): if each['name'] == interface['name']: break else: + # configuring non-existing interface + commands.extend(self._set_config(interface, dict())) continue commands.extend(self._set_config(interface, each))