mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
fix nxapi transport in nxos_snmp_location (#27849)
* fix nxapi transport in nxos_snmp_location * Appease Shippable
This commit is contained in:
parent
c1bf74283e
commit
01dda25e0f
2 changed files with 23 additions and 65 deletions
|
@ -51,67 +51,42 @@ EXAMPLES = '''
|
||||||
- nxos_snmp_location:
|
- nxos_snmp_location:
|
||||||
location: Test
|
location: Test
|
||||||
state: present
|
state: present
|
||||||
host: "{{ inventory_hostname }}"
|
|
||||||
username: "{{ un }}"
|
|
||||||
password: "{{ pwd }}"
|
|
||||||
|
|
||||||
# ensure snmp location is not configured
|
# ensure snmp location is not configured
|
||||||
- nxos_snmp_location:
|
- nxos_snmp_location:
|
||||||
location: Test
|
location: Test
|
||||||
state: absent
|
state: absent
|
||||||
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: {"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:
|
|
||||||
description: command sent to the device
|
description: command sent to the device
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample: ["snmp-server location New_Test"]
|
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 get_config, 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
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
def execute_show_command(command, module, command_type='cli_show'):
|
def execute_show_command(command, module, command_type='cli_show'):
|
||||||
if module.params['transport'] == 'cli':
|
if 'show run' not in command:
|
||||||
if 'show run' not in command:
|
cmds = [{
|
||||||
command += ' | json'
|
'command': command,
|
||||||
cmds = [command]
|
'output': 'json',
|
||||||
body = run_commands(module, cmds)
|
}]
|
||||||
elif module.params['transport'] == 'nxapi':
|
else:
|
||||||
cmds = [command]
|
cmds = [{
|
||||||
body = run_commands(module, cmds)
|
'command': command,
|
||||||
|
'output': 'text',
|
||||||
|
}]
|
||||||
|
|
||||||
return body
|
return run_commands(module, cmds)
|
||||||
|
|
||||||
|
|
||||||
def apply_key_map(key_map, table):
|
def apply_key_map(key_map, table):
|
||||||
|
@ -119,7 +94,6 @@ def apply_key_map(key_map, table):
|
||||||
for key, value in table.items():
|
for key, value in table.items():
|
||||||
new_key = key_map.get(key)
|
new_key = key_map.get(key)
|
||||||
if new_key:
|
if new_key:
|
||||||
value = table.get(key)
|
|
||||||
if value:
|
if value:
|
||||||
new_dict[new_key] = str(value)
|
new_dict[new_key] = str(value)
|
||||||
else:
|
else:
|
||||||
|
@ -156,25 +130,21 @@ def get_snmp_location(module):
|
||||||
def main():
|
def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
location=dict(required=True, type='str'),
|
location=dict(required=True, type='str'),
|
||||||
state=dict(choices=['absent', 'present'],
|
state=dict(choices=['absent', 'present'], 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 = {'commands': [], 'changed': False, 'warnings': warnings}
|
||||||
|
|
||||||
|
|
||||||
location = module.params['location']
|
location = module.params['location']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
existing = get_snmp_location(module)
|
existing = get_snmp_location(module)
|
||||||
changed = False
|
|
||||||
commands = []
|
commands = []
|
||||||
proposed = dict(location=location)
|
proposed = dict(location=location)
|
||||||
end_state = existing
|
end_state = existing
|
||||||
|
@ -188,27 +158,16 @@ def main():
|
||||||
|
|
||||||
cmds = flatten_list(commands)
|
cmds = flatten_list(commands)
|
||||||
if cmds:
|
if cmds:
|
||||||
if module.check_mode:
|
if not module.check_mode:
|
||||||
module.exit_json(changed=True, commands=cmds)
|
|
||||||
else:
|
|
||||||
changed = True
|
|
||||||
load_config(module, cmds)
|
load_config(module, cmds)
|
||||||
end_state = get_snmp_location(module)
|
|
||||||
if 'configure' in cmds:
|
|
||||||
cmds.pop(0)
|
|
||||||
|
|
||||||
results = {}
|
if 'configure' in cmds:
|
||||||
results['proposed'] = proposed
|
cmds.pop(0)
|
||||||
results['existing'] = existing
|
results['commands'] = cmds
|
||||||
results['end_state'] = end_state
|
results['changed'] = True
|
||||||
results['updates'] = cmds
|
|
||||||
results['changed'] = changed
|
|
||||||
results['warnings'] = warnings
|
|
||||||
|
|
||||||
module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
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_community.py
|
||||||
lib/ansible/modules/network/nxos/nxos_snmp_contact.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_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_traps.py
|
||||||
lib/ansible/modules/network/nxos/nxos_snmp_user.py
|
lib/ansible/modules/network/nxos/nxos_snmp_user.py
|
||||||
lib/ansible/modules/network/nxos/nxos_static_route.py
|
lib/ansible/modules/network/nxos/nxos_static_route.py
|
||||||
|
|
Loading…
Reference in a new issue