mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
[WIP] Fix nxos_banner (#28607)
* Fix `'state': 'absent'` * Replace idempotence tests with references * Fix issues with nxos_banner
This commit is contained in:
parent
0a8ec4ddef
commit
862cde5e82
4 changed files with 16 additions and 46 deletions
|
@ -92,28 +92,25 @@ from ansible.module_utils.nxos import load_config, run_commands
|
|||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module):
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
want, have = updates
|
||||
state = module.params['state']
|
||||
|
||||
if state == 'absent' or (state == 'absent' and
|
||||
'text' in have.keys() and have['text']):
|
||||
if state == 'absent' and have.get('text'):
|
||||
commands.append('no banner %s' % module.params['banner'])
|
||||
|
||||
elif state == 'present':
|
||||
if want['text'] and (want['text'] != have.get('text')):
|
||||
banner_cmd = 'banner %s' % module.params['banner']
|
||||
banner_cmd += ' @\n'
|
||||
banner_cmd += want['text'].strip()
|
||||
banner_cmd += '\n@'
|
||||
commands.append(banner_cmd)
|
||||
elif state == 'present' and want.get('text') != have.get('text'):
|
||||
banner_cmd = 'banner %s @\n%s\n@' % (module.params['banner'], want['text'].strip())
|
||||
commands.append(banner_cmd)
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
output = run_commands(module, ['show banner %s' % module.params['banner']])[0]
|
||||
if isinstance(output, dict):
|
||||
output = list(output.values())[0]
|
||||
|
||||
obj = {'banner': module.params['banner'], 'state': 'absent'}
|
||||
if output:
|
||||
obj['text'] = output
|
||||
|
@ -159,7 +156,7 @@ def main():
|
|||
want = map_params_to_obj(module)
|
||||
have = map_config_to_obj(module)
|
||||
|
||||
commands = map_obj_to_commands((want, have), module)
|
||||
commands = map_obj_to_commands(want, have, module)
|
||||
result['commands'] = commands
|
||||
|
||||
if commands:
|
||||
|
@ -169,5 +166,6 @@ def main():
|
|||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue