Insert set commands if a delete command is entered (#40666) (#40672)

(cherry picked from commit 8b4e36e711)
pull/40788/head
Sam Doran 7 years ago committed by GitHub
parent d6a07186fd
commit b20b29ac0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- edgeos_config - check for a corresponding set command when issuing delete commands to ensure the desired state is met (https://github.com/ansible/ansible/issues/40437)

@ -179,6 +179,7 @@ def diff_config(commands, config):
updates = list()
visited = set()
delete_commands = [line for line in commands if line.startswith('delete')]
for line in commands:
item = to_native(line).replace("'", '')
@ -186,8 +187,18 @@ def diff_config(commands, config):
if not item.startswith('set') and not item.startswith('delete'):
raise ValueError('line must start with either `set` or `delete`')
elif item.startswith('set') and item not in config:
updates.append(line)
elif item.startswith('set'):
if item not in config:
updates.append(line)
# If there is a corresponding delete command in the desired config, make sure to append
# the set command even though it already exists in the running config
else:
ditem = re.sub('set', 'delete', item)
for line in delete_commands:
if ditem.startswith(line):
updates.append(item)
elif item.startswith('delete'):
if not config:

Loading…
Cancel
Save