fix nxapi transport in nxos_snmp_location (#27849)

* fix nxapi transport in nxos_snmp_location

* Appease Shippable
pull/27962/head
Nathaniel Case 7 years ago committed by GitHub
parent c1bf74283e
commit 01dda25e0f

@ -51,67 +51,42 @@ EXAMPLES = '''
- nxos_snmp_location:
location: Test
state: present
host: "{{ inventory_hostname }}"
username: "{{ un }}"
password: "{{ pwd }}"
# ensure snmp location is not configured
- nxos_snmp_location:
location: Test
state: absent
host: "{{ inventory_hostname }}"
username: "{{ un }}"
password: "{{ pwd }}"
'''
RETURN = '''
proposed:
description: k/v pairs of parameters passed into module
returned: always
type: dict
sample: {"location": "New_Test"}
existing:
description: k/v pairs of existing snmp location
returned: always
type: dict
sample: {"location": "Test"}
end_state:
description: k/v pairs of location info after module execution
returned: always
type: dict
sample: {"location": "New_Test"}
updates:
commands:
description: command sent to the device
returned: always
type: list
sample: ["snmp-server location New_Test"]
changed:
description: check to see if a change was made on the device
returned: always
type: boolean
sample: true
'''
import re
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
import re
import re
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
cmds = [{
'command': command,
'output': 'json',
}]
else:
cmds = [{
'command': command,
'output': 'text',
}]
return body
return run_commands(module, cmds)
def apply_key_map(key_map, table):
@ -119,7 +94,6 @@ def apply_key_map(key_map, table):
for key, value in table.items():
new_key = key_map.get(key)
if new_key:
value = table.get(key)
if value:
new_dict[new_key] = str(value)
else:
@ -156,25 +130,21 @@ def get_snmp_location(module):
def main():
argument_spec = dict(
location=dict(required=True, type='str'),
state=dict(choices=['absent', 'present'],
default='present')
state=dict(choices=['absent', 'present'], default='present')
)
argument_spec.update(nxos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
warnings = list()
check_args(module, warnings)
results = {'commands': [], 'changed': False, 'warnings': warnings}
location = module.params['location']
state = module.params['state']
existing = get_snmp_location(module)
changed = False
commands = []
proposed = dict(location=location)
end_state = existing
@ -188,27 +158,16 @@ def main():
cmds = flatten_list(commands)
if cmds:
if module.check_mode:
module.exit_json(changed=True, commands=cmds)
else:
changed = True
if not module.check_mode:
load_config(module, cmds)
end_state = get_snmp_location(module)
if 'configure' in cmds:
cmds.pop(0)
results = {}
results['proposed'] = proposed
results['existing'] = existing
results['end_state'] = end_state
results['updates'] = cmds
results['changed'] = changed
results['warnings'] = warnings
results['commands'] = cmds
results['changed'] = True
module.exit_json(**results)
from ansible.module_utils.basic import *
if __name__ == "__main__":
main()

@ -332,7 +332,6 @@ lib/ansible/modules/network/nxos/nxos_snapshot.py
lib/ansible/modules/network/nxos/nxos_snmp_community.py
lib/ansible/modules/network/nxos/nxos_snmp_contact.py
lib/ansible/modules/network/nxos/nxos_snmp_host.py
lib/ansible/modules/network/nxos/nxos_snmp_location.py
lib/ansible/modules/network/nxos/nxos_snmp_traps.py
lib/ansible/modules/network/nxos/nxos_snmp_user.py
lib/ansible/modules/network/nxos/nxos_static_route.py

Loading…
Cancel
Save