mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix vyos_banner multiline string issue (#26383)
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
df0864d801
commit
ad3fe08aae
4 changed files with 8 additions and 11 deletions
|
@ -100,11 +100,9 @@ def spec_to_commands(updates, module):
|
||||||
commands.append('delete system login banner %s' % module.params['banner'])
|
commands.append('delete system login banner %s' % module.params['banner'])
|
||||||
|
|
||||||
elif state == 'present':
|
elif state == 'present':
|
||||||
if want['text'] and (want['text'] != have.get('text')):
|
if want['text'] and want['text'].encode().decode('unicode_escape') != have.get('text'):
|
||||||
banner_cmd = 'set system login banner %s ' % module.params['banner']
|
banner_cmd = 'set system login banner %s ' % module.params['banner']
|
||||||
banner_cmd += "'"
|
|
||||||
banner_cmd += want['text'].strip()
|
banner_cmd += want['text'].strip()
|
||||||
banner_cmd += "'"
|
|
||||||
commands.append(banner_cmd)
|
commands.append(banner_cmd)
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
@ -119,9 +117,8 @@ def config_to_dict(module):
|
||||||
if line.startswith('set system login banner %s' % obj['banner']):
|
if line.startswith('set system login banner %s' % obj['banner']):
|
||||||
match = re.findall(r'%s (.*)' % obj['banner'], line, re.M)
|
match = re.findall(r'%s (.*)' % obj['banner'], line, re.M)
|
||||||
output = match
|
output = match
|
||||||
|
|
||||||
if output:
|
if output:
|
||||||
obj['text'] = output[0][1:-1]
|
obj['text'] = output[0].encode().decode('unicode_escape')
|
||||||
obj['state'] = 'present'
|
obj['state'] = 'present'
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
@ -130,7 +127,7 @@ def config_to_dict(module):
|
||||||
def map_params_to_obj(module):
|
def map_params_to_obj(module):
|
||||||
text = module.params['text']
|
text = module.params['text']
|
||||||
if text:
|
if text:
|
||||||
text = str(text).strip()
|
text = "%r" % (str(text).strip())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'banner': module.params['banner'],
|
'banner': module.params['banner'],
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.changed == true"
|
- "result.changed == true"
|
||||||
- "'this is my post-login banner' in result.commands"
|
- "'this is my post-login banner' in result.commands[0]"
|
||||||
- "'that has a multiline' in result.commands"
|
- "'that has a multiline' in result.commands[0]"
|
||||||
|
|
||||||
- name: Set post-login again (idempotent)
|
- name: Set post-login again (idempotent)
|
||||||
vyos_banner:
|
vyos_banner:
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- "result.changed == true"
|
- "result.changed == true"
|
||||||
- "'this is my pre-login banner' in result.commands"
|
- "'this is my pre-login banner' in result.commands[0]"
|
||||||
- "'that has a multiline' in result.commands"
|
- "'that has a multiline' in result.commands[0]"
|
||||||
|
|
||||||
- name: Set pre-login again (idempotent)
|
- name: Set pre-login again (idempotent)
|
||||||
vyos_banner:
|
vyos_banner:
|
||||||
|
|
|
@ -44,7 +44,7 @@ class TestVyosBannerModule(TestVyosModule):
|
||||||
|
|
||||||
def test_vyos_banner_create(self):
|
def test_vyos_banner_create(self):
|
||||||
set_module_args(dict(banner='pre-login', text='test\nbanner\nstring'))
|
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)
|
self.execute_module(changed=True, commands=commands)
|
||||||
|
|
||||||
def test_vyos_banner_remove(self):
|
def test_vyos_banner_remove(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue