|
|
@ -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
|
|
|
|
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()
|
|
|
|
commands = list()
|
|
|
|
want, have = updates
|
|
|
|
|
|
|
|
state = module.params['state']
|
|
|
|
state = module.params['state']
|
|
|
|
|
|
|
|
|
|
|
|
if state == 'absent' or (state == 'absent' and
|
|
|
|
if state == 'absent' and have.get('text'):
|
|
|
|
'text' in have.keys() and have['text']):
|
|
|
|
|
|
|
|
commands.append('no banner %s' % module.params['banner'])
|
|
|
|
commands.append('no banner %s' % module.params['banner'])
|
|
|
|
|
|
|
|
|
|
|
|
elif state == 'present':
|
|
|
|
elif state == 'present' and want.get('text') != have.get('text'):
|
|
|
|
if want['text'] and (want['text'] != have.get('text')):
|
|
|
|
banner_cmd = 'banner %s @\n%s\n@' % (module.params['banner'], want['text'].strip())
|
|
|
|
banner_cmd = 'banner %s' % module.params['banner']
|
|
|
|
commands.append(banner_cmd)
|
|
|
|
banner_cmd += ' @\n'
|
|
|
|
|
|
|
|
banner_cmd += want['text'].strip()
|
|
|
|
|
|
|
|
banner_cmd += '\n@'
|
|
|
|
|
|
|
|
commands.append(banner_cmd)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return commands
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def map_config_to_obj(module):
|
|
|
|
def map_config_to_obj(module):
|
|
|
|
output = run_commands(module, ['show banner %s' % module.params['banner']])[0]
|
|
|
|
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'}
|
|
|
|
obj = {'banner': module.params['banner'], 'state': 'absent'}
|
|
|
|
if output:
|
|
|
|
if output:
|
|
|
|
obj['text'] = output
|
|
|
|
obj['text'] = output
|
|
|
@ -159,7 +156,7 @@ def main():
|
|
|
|
want = map_params_to_obj(module)
|
|
|
|
want = map_params_to_obj(module)
|
|
|
|
have = map_config_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
|
|
|
|
result['commands'] = commands
|
|
|
|
|
|
|
|
|
|
|
|
if commands:
|
|
|
|
if commands:
|
|
|
@ -169,5 +166,6 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
main()
|
|
|
|