diff --git a/lib/ansible/modules/network/vyos/vyos_banner.py b/lib/ansible/modules/network/vyos/vyos_banner.py index 238fa42006..5038209870 100644 --- a/lib/ansible/modules/network/vyos/vyos_banner.py +++ b/lib/ansible/modules/network/vyos/vyos_banner.py @@ -94,16 +94,17 @@ def spec_to_commands(updates, module): want, have = updates state = module.params['state'] - if state == 'absent' or (state == 'absent' and - 'text' in have.keys() and have['text']): - commands.append('delete system login banner %s' % module.params['banner']) + if state == 'absent': + if have.get('state') != 'absent' or (have.get('state') != 'absent' and + 'text' in have.keys() and have['text']): + commands.append('delete system login banner %s' % module.params['banner']) elif state == 'present': if want['text'] and (want['text'] != have.get('text')): banner_cmd = 'set system login banner %s ' % module.params['banner'] - banner_cmd += '"' + banner_cmd += "'" banner_cmd += want['text'].strip() - banner_cmd += '"' + banner_cmd += "'" commands.append(banner_cmd) return commands @@ -120,7 +121,7 @@ def config_to_dict(module): output = match if output: - obj['text'] = output + obj['text'] = output[0][1:-1] obj['state'] = 'present' return obj diff --git a/test/units/modules/network/vyos/test_vyos_banner.py b/test/units/modules/network/vyos/test_vyos_banner.py index 8ff923e074..b8e454cf4e 100644 --- a/test/units/modules/network/vyos/test_vyos_banner.py +++ b/test/units/modules/network/vyos/test_vyos_banner.py @@ -44,10 +44,10 @@ class TestVyosBannerModule(TestVyosModule): def test_vyos_banner_create(self): set_module_args(dict(banner='pre-login', text='test\nbanner\nstring')) - commands = ['set system login banner pre-login "test\nbanner\nstring"'] + commands = ["set system login banner pre-login 'test\nbanner\nstring'"] self.execute_module(changed=True, commands=commands) def test_vyos_banner_remove(self): set_module_args(dict(banner='pre-login', state='absent')) commands = ['delete system login banner pre-login'] - self.execute_module(changed=True, commands=commands) + self.execute_module(changed=False, commands=[])