Clean up nxos_aaa_server (#28177)
* cleanup nxos_aaa_server * Specify nxos_aaa_server output format Fixes #27289
This commit is contained in:
parent
5739bb075f
commit
1d13624eae
2 changed files with 16 additions and 72 deletions
|
@ -95,9 +95,6 @@ EXAMPLES = '''
|
||||||
server_timeout: 9
|
server_timeout: 9
|
||||||
deadtime: 20
|
deadtime: 20
|
||||||
directed_request: enabled
|
directed_request: enabled
|
||||||
host: inventory_hostname }}
|
|
||||||
username: un }}
|
|
||||||
password: pwd }}
|
|
||||||
|
|
||||||
# Tacacs Server Basic settings
|
# Tacacs Server Basic settings
|
||||||
- name: "Tacacs Server Basic settings"
|
- name: "Tacacs Server Basic settings"
|
||||||
|
@ -106,56 +103,21 @@ EXAMPLES = '''
|
||||||
server_timeout: 8
|
server_timeout: 8
|
||||||
deadtime: 19
|
deadtime: 19
|
||||||
directed_request: disabled
|
directed_request: disabled
|
||||||
host: inventory_hostname }}
|
|
||||||
username: un }}
|
|
||||||
password: pwd }}
|
|
||||||
|
|
||||||
# Setting Global Key
|
# Setting Global Key
|
||||||
- name: "AAA Server Global Key"
|
- name: "AAA Server Global Key"
|
||||||
nxos_aaa_server:
|
nxos_aaa_server:
|
||||||
server_type: radius
|
server_type: radius
|
||||||
global_key: test_key
|
global_key: test_key
|
||||||
host: inventory_hostname }}
|
|
||||||
username: un }}
|
|
||||||
password: pwd }}
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
proposed:
|
commands:
|
||||||
description: k/v pairs of parameters passed into module
|
|
||||||
returned: always
|
|
||||||
type: dict
|
|
||||||
sample: {"deadtime": "22", "directed_request": "enabled",
|
|
||||||
"server_type": "radius", "server_timeout": "11"}
|
|
||||||
existing:
|
|
||||||
description:
|
|
||||||
- k/v pairs of existing aaa server
|
|
||||||
returned: always
|
|
||||||
type: dict
|
|
||||||
sample: {"deadtime": "0", "directed_request": "disabled",
|
|
||||||
"global_key": "unknown", "server_timeout": "5"}
|
|
||||||
end_state:
|
|
||||||
description: k/v pairs of aaa params after module execution
|
|
||||||
returned: always
|
|
||||||
type: dict
|
|
||||||
sample: {"deadtime": "22", "directed_request": "enabled",
|
|
||||||
"global_key": "unknown", "server_timeout": "11"}
|
|
||||||
state:
|
|
||||||
description: state as sent in from the playbook
|
|
||||||
returned: always
|
|
||||||
type: string
|
|
||||||
sample: "present"
|
|
||||||
updates:
|
|
||||||
description: command sent to the device
|
description: command sent to the device
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample: ["radius-server deadtime 22", "radius-server timeout 11",
|
sample: ["radius-server deadtime 22", "radius-server timeout 11",
|
||||||
"radius-server directed-request"]
|
"radius-server directed-request"]
|
||||||
changed:
|
|
||||||
description: check to see if a change was made on the device
|
|
||||||
returned: always
|
|
||||||
type: boolean
|
|
||||||
sample: true
|
|
||||||
'''
|
'''
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -165,12 +127,12 @@ from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
def execute_show_command(command, module, command_type='cli_show'):
|
def execute_show_command(command, module, command_type='cli_show'):
|
||||||
cmds = [command]
|
command = {
|
||||||
if module.params['transport'] == 'cli':
|
'command': command,
|
||||||
body = run_commands(module, cmds)
|
'output': 'text',
|
||||||
elif module.params['transport'] == 'nxapi':
|
}
|
||||||
body = run_commands(module, cmds)
|
|
||||||
return body
|
return run_commands(module, command)
|
||||||
|
|
||||||
|
|
||||||
def flatten_list(command_lists):
|
def flatten_list(command_lists):
|
||||||
|
@ -183,7 +145,6 @@ def flatten_list(command_lists):
|
||||||
return flat_command_list
|
return flat_command_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_aaa_server_info(server_type, module):
|
def get_aaa_server_info(server_type, module):
|
||||||
aaa_server_info = {}
|
aaa_server_info = {}
|
||||||
server_command = 'show {0}-server'.format(server_type)
|
server_command = 'show {0}-server'.format(server_type)
|
||||||
|
@ -281,25 +242,22 @@ def default_aaa_server(existing, params, server_type):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
server_type=dict(type='str',
|
server_type=dict(type='str', choices=['radius', 'tacacs'], required=True),
|
||||||
choices=['radius', 'tacacs'], required=True),
|
|
||||||
global_key=dict(type='str'),
|
global_key=dict(type='str'),
|
||||||
encrypt_type=dict(type='str', choices=['0', '7']),
|
encrypt_type=dict(type='str', choices=['0', '7']),
|
||||||
deadtime=dict(type='str'),
|
deadtime=dict(type='str'),
|
||||||
server_timeout=dict(type='str'),
|
server_timeout=dict(type='str'),
|
||||||
directed_request=dict(type='str',
|
directed_request=dict(type='str', choices=['enabled', 'disabled', 'default']),
|
||||||
choices=['enabled', 'disabled', 'default']),
|
|
||||||
state=dict(choices=['default', 'present'], default='present'),
|
state=dict(choices=['default', 'present'], default='present'),
|
||||||
)
|
)
|
||||||
|
|
||||||
argument_spec.update(nxos_argument_spec)
|
argument_spec.update(nxos_argument_spec)
|
||||||
|
|
||||||
module = AnsibleModule(argument_spec=argument_spec,
|
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
|
||||||
supports_check_mode=True)
|
|
||||||
|
|
||||||
warnings = list()
|
warnings = list()
|
||||||
check_args(module, warnings)
|
check_args(module, warnings)
|
||||||
|
results = {'changed': False, 'commands': [], 'warnings': warnings}
|
||||||
|
|
||||||
server_type = module.params['server_type']
|
server_type = module.params['server_type']
|
||||||
global_key = module.params['global_key']
|
global_key = module.params['global_key']
|
||||||
|
@ -316,11 +274,9 @@ def main():
|
||||||
encrypt_type=encrypt_type, deadtime=deadtime,
|
encrypt_type=encrypt_type, deadtime=deadtime,
|
||||||
server_timeout=server_timeout, directed_request=directed_request)
|
server_timeout=server_timeout, directed_request=directed_request)
|
||||||
|
|
||||||
changed = False
|
|
||||||
proposed = dict((k, v) for k, v in args.items() if v is not None)
|
proposed = dict((k, v) for k, v in args.items() if v is not None)
|
||||||
|
|
||||||
existing = get_aaa_server_info(server_type, module)
|
existing = get_aaa_server_info(server_type, module)
|
||||||
end_state = existing
|
|
||||||
|
|
||||||
commands = []
|
commands = []
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
|
@ -359,26 +315,15 @@ def main():
|
||||||
|
|
||||||
cmds = flatten_list(commands)
|
cmds = flatten_list(commands)
|
||||||
if cmds:
|
if cmds:
|
||||||
if module.check_mode:
|
results['changed'] = True
|
||||||
module.exit_json(changed=True, commands=cmds)
|
if not module.check_mode:
|
||||||
else:
|
|
||||||
changed = True
|
|
||||||
load_config(module, cmds)
|
load_config(module, cmds)
|
||||||
end_state = get_aaa_server_info(server_type, module)
|
|
||||||
if 'configure' in cmds:
|
if 'configure' in cmds:
|
||||||
cmds.pop(0)
|
cmds.pop(0)
|
||||||
|
results['commands'] = cmds
|
||||||
results = {}
|
|
||||||
results['proposed'] = proposed
|
|
||||||
results['existing'] = existing
|
|
||||||
results['updates'] = cmds
|
|
||||||
results['changed'] = changed
|
|
||||||
results['warnings'] = warnings
|
|
||||||
results['end_state'] = end_state
|
|
||||||
|
|
||||||
module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
@ -300,7 +300,6 @@ lib/ansible/modules/network/netvisor/pn_vrouterif.py
|
||||||
lib/ansible/modules/network/netvisor/pn_vrouterlbif.py
|
lib/ansible/modules/network/netvisor/pn_vrouterlbif.py
|
||||||
lib/ansible/modules/net_tools/nmcli.py
|
lib/ansible/modules/net_tools/nmcli.py
|
||||||
lib/ansible/modules/network/nxos/_nxos_mtu.py
|
lib/ansible/modules/network/nxos/_nxos_mtu.py
|
||||||
lib/ansible/modules/network/nxos/nxos_aaa_server.py
|
|
||||||
lib/ansible/modules/network/nxos/nxos_aaa_server_host.py
|
lib/ansible/modules/network/nxos/nxos_aaa_server_host.py
|
||||||
lib/ansible/modules/network/nxos/nxos_command.py
|
lib/ansible/modules/network/nxos/nxos_command.py
|
||||||
lib/ansible/modules/network/nxos/nxos_config.py
|
lib/ansible/modules/network/nxos/nxos_config.py
|
||||||
|
|
Loading…
Reference in a new issue