mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
fix iosxr_banner (#27378)
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
26c9007c2d
commit
6d1bd33aa5
5 changed files with 22 additions and 64 deletions
|
@ -87,6 +87,8 @@ commands:
|
|||
- string
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.iosxr import get_config, load_config
|
||||
from ansible.module_utils.iosxr import iosxr_argument_spec, check_args
|
||||
|
@ -97,12 +99,13 @@ def map_obj_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('no banner %s' % module.params['banner'])
|
||||
if state == 'absent':
|
||||
if have.get('state') != 'absent' and ('text' in have.keys() and have['text']):
|
||||
commands.append('no banner %s' % module.params['banner'])
|
||||
|
||||
elif state == 'present':
|
||||
if want['text'] and (want['text'] != have.get('text')):
|
||||
if (want['text'] and
|
||||
want['text'].encode().decode('unicode_escape').strip("'") != have.get('text')):
|
||||
banner_cmd = 'banner %s ' % module.params['banner']
|
||||
banner_cmd += want['text'].strip()
|
||||
commands.append(banner_cmd)
|
||||
|
@ -113,9 +116,17 @@ def map_obj_to_commands(updates, module):
|
|||
def map_config_to_obj(module):
|
||||
flags = 'banner %s' % module.params['banner']
|
||||
output = get_config(module, flags=[flags])
|
||||
|
||||
match = re.search(r'banner (\S+) (.*)', output, re.DOTALL)
|
||||
if match:
|
||||
text = match.group(2).strip("'")
|
||||
else:
|
||||
text = None
|
||||
|
||||
obj = {'banner': module.params['banner'], 'state': 'absent'}
|
||||
|
||||
if output:
|
||||
obj['text'] = output
|
||||
obj['text'] = text
|
||||
obj['state'] = 'present'
|
||||
|
||||
return obj
|
||||
|
@ -124,7 +135,7 @@ def map_config_to_obj(module):
|
|||
def map_params_to_obj(module):
|
||||
text = module.params['text']
|
||||
if text:
|
||||
text = str(text).strip()
|
||||
text = "%r" % (str(text).strip())
|
||||
|
||||
return {
|
||||
'banner': module.params['banner'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue