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)