From 95a75e7c3a9d4dcb0ec823a26deb7f96cb94cef7 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Sat, 4 Feb 2017 19:46:16 +0530 Subject: [PATCH] Fixes #20412 junos_config delete command fix (#20450) If same config hierarchy is set and deleted in one playbook for delete statement add support to check if the config is present on device or in the playbook. If it is present add delete statement in updated config list. --- lib/ansible/modules/network/junos/junos_config.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/network/junos/junos_config.py b/lib/ansible/modules/network/junos/junos_config.py index 60cbee42d3b..b44f1c012c6 100644 --- a/lib/ansible/modules/network/junos/junos_config.py +++ b/lib/ansible/modules/network/junos/junos_config.py @@ -237,7 +237,7 @@ def diff_commands(commands, config): updates = list() visited = set() - for item in commands: + for index, item in enumerate(commands): if len(item) > 0: if not item.startswith('set') and not item.startswith('delete'): raise ValueError('line must start with either `set` or `delete`') @@ -246,7 +246,9 @@ def diff_commands(commands, config): updates.append(item) elif item.startswith('delete'): - for entry in config: + for entry in config + commands[0:index]: + if entry.startswith('set'): + entry = entry[4:] if entry.startswith(item[7:]) and item not in visited: updates.append(item) visited.add(item)