diff --git a/lib/ansible/modules/network/vyos/vyos_config.py b/lib/ansible/modules/network/vyos/vyos_config.py index 6c2b5f07d4..c4f0e8c948 100644 --- a/lib/ansible/modules/network/vyos/vyos_config.py +++ b/lib/ansible/modules/network/vyos/vyos_config.py @@ -146,12 +146,17 @@ CONFIG_FILTERS = [ def get_candidate(module): contents = module.params['src'] or module.params['lines'] - if module.params['lines']: - contents = '\n'.join(contents) + if module.params['src']: + contents = format_commands(contents.splitlines()) + contents = '\n'.join(contents) return contents +def format_commands(commands): + return [line for line in commands if len(line.strip()) > 0] + + def diff_config(commands, config): config = [str(c).replace("'", '') for c in config.splitlines()] diff --git a/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg b/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg index ca6abebc9a..18cd793718 100644 --- a/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg +++ b/test/units/modules/network/vyos/fixtures/vyos_config_src.cfg @@ -1,4 +1,5 @@ set system host-name foo + delete interfaces ethernet eth0 address set interfaces ethernet eth1 address '6.7.8.9/24' set interfaces ethernet eth1 description 'test string' diff --git a/test/units/modules/network/vyos/test_vyos_config.py b/test/units/modules/network/vyos/test_vyos_config.py index bd73b7540e..a923193af9 100644 --- a/test/units/modules/network/vyos/test_vyos_config.py +++ b/test/units/modules/network/vyos/test_vyos_config.py @@ -75,15 +75,17 @@ class TestVyosConfigModule(TestVyosModule): def test_vyos_config_src(self): src = load_fixture('vyos_config_src.cfg') set_module_args(dict(src=src)) + candidate = '\n'.join(self.module.format_commands(src.splitlines())) commands = ['set system host-name foo', 'delete interfaces ethernet eth0 address'] - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config)) + self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config)) self.execute_module(changed=True, commands=commands) def test_vyos_config_src_brackets(self): src = load_fixture('vyos_config_src_brackets.cfg') set_module_args(dict(src=src)) + candidate = '\n'.join(self.module.format_commands(src.splitlines())) commands = ['set interfaces ethernet eth0 address 10.10.10.10/24', 'set system host-name foo'] - self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(src, self.running_config)) + self.conn.get_diff = MagicMock(return_value=self.cliconf_obj.get_diff(candidate, self.running_config)) self.execute_module(changed=True, commands=commands) def test_vyos_config_backup(self):