From 4dc09e19ea6b1ef9d87659d90ab512f42a9f6a1f Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Mon, 10 Oct 2016 12:37:21 -0400 Subject: [PATCH] fixes bug with junos_config module not properly loading config (#5213) This fixes two issues. First, it fixes an issue with the junos_config module not properly recognizing a file with set commands. The second bug would cause the diff_config() function to raise an exception due to a blank line when splitting the config --- .../modules/network/junos/junos_config.py | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/ansible/modules/network/junos/junos_config.py b/lib/ansible/modules/network/junos/junos_config.py index efab50a41e7..6328fb55732 100644 --- a/lib/ansible/modules/network/junos/junos_config.py +++ b/lib/ansible/modules/network/junos/junos_config.py @@ -217,18 +217,19 @@ def diff_commands(commands, config): updates = list() visited = set() - for item in commands: - 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[4:] not in config: - updates.append(item) - - elif item.startswith('delete'): - for entry in config: - if entry.startswith(item[7:]) and item not in visited: - updates.append(item) - visited.add(item) + for item in commands.split('\n'): + if len(item) > 0: + 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[4:] not in config: + updates.append(item) + + elif item.startswith('delete'): + for entry in config: + if entry.startswith(item[7:]) and item not in visited: + updates.append(item) + visited.add(item) return updates