|
|
@ -67,59 +67,31 @@ EXAMPLES = '''
|
|
|
|
community: TESTING7
|
|
|
|
community: TESTING7
|
|
|
|
group: network-operator
|
|
|
|
group: network-operator
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
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: {"group": "network-operator"}
|
|
|
|
|
|
|
|
existing:
|
|
|
|
|
|
|
|
description: k/v pairs of existing snmp community
|
|
|
|
|
|
|
|
returned: always
|
|
|
|
|
|
|
|
type: dict
|
|
|
|
|
|
|
|
sample: {}
|
|
|
|
|
|
|
|
end_state:
|
|
|
|
|
|
|
|
description: k/v pairs of snmp community after module execution
|
|
|
|
|
|
|
|
returned: always
|
|
|
|
|
|
|
|
type: dict
|
|
|
|
|
|
|
|
sample: {"acl": "None", "group": "network-operator"}
|
|
|
|
|
|
|
|
updates:
|
|
|
|
|
|
|
|
description: commands sent to the device
|
|
|
|
description: commands sent to the device
|
|
|
|
returned: always
|
|
|
|
returned: always
|
|
|
|
type: list
|
|
|
|
type: list
|
|
|
|
sample: ["snmp-server community TESTING7 group network-operator"]
|
|
|
|
sample: ["snmp-server community TESTING7 group network-operator"]
|
|
|
|
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
|
|
|
|
def execute_show_command(command, module):
|
|
|
|
import re
|
|
|
|
command = {
|
|
|
|
|
|
|
|
'command': command,
|
|
|
|
|
|
|
|
'output': 'json',
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return body
|
|
|
|
return run_commands(module, [command])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def apply_key_map(key_map, table):
|
|
|
|
def apply_key_map(key_map, table):
|
|
|
@ -127,7 +99,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:
|
|
|
@ -178,7 +149,7 @@ def get_snmp_community(module, find_filter=None):
|
|
|
|
community = apply_key_map(community_map, each)
|
|
|
|
community = apply_key_map(community_map, each)
|
|
|
|
key = each['community_name']
|
|
|
|
key = each['community_name']
|
|
|
|
community_dict[key] = community
|
|
|
|
community_dict[key] = community
|
|
|
|
except (KeyError, AttributeError):
|
|
|
|
except (KeyError, AttributeError, TypeError):
|
|
|
|
return community_dict
|
|
|
|
return community_dict
|
|
|
|
|
|
|
|
|
|
|
|
if find_filter:
|
|
|
|
if find_filter:
|
|
|
@ -222,13 +193,13 @@ def main():
|
|
|
|
argument_spec.update(nxos_argument_spec)
|
|
|
|
argument_spec.update(nxos_argument_spec)
|
|
|
|
|
|
|
|
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec,
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec,
|
|
|
|
required_one_of=[['access', 'group']],
|
|
|
|
required_one_of=[['access', 'group']],
|
|
|
|
mutually_exclusive=[['access', 'group']],
|
|
|
|
mutually_exclusive=[['access', 'group']],
|
|
|
|
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}
|
|
|
|
|
|
|
|
|
|
|
|
access = module.params['access']
|
|
|
|
access = module.params['access']
|
|
|
|
group = module.params['group']
|
|
|
|
group = module.params['group']
|
|
|
@ -246,46 +217,31 @@ def main():
|
|
|
|
configured_groups = get_snmp_groups(module)
|
|
|
|
configured_groups = get_snmp_groups(module)
|
|
|
|
|
|
|
|
|
|
|
|
if group not in configured_groups:
|
|
|
|
if group not in configured_groups:
|
|
|
|
module.fail_json(msg="group not on switch."
|
|
|
|
module.fail_json(msg="Group not on switch. Please add before moving forward")
|
|
|
|
"please add before moving forward")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
existing = get_snmp_community(module, community)
|
|
|
|
existing = get_snmp_community(module, community)
|
|
|
|
args = dict(group=group, acl=acl)
|
|
|
|
args = dict(group=group, acl=acl)
|
|
|
|
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)
|
|
|
|
delta = dict(set(proposed.items()).difference(existing.items()))
|
|
|
|
delta = dict(set(proposed.items()).difference(existing.items()))
|
|
|
|
|
|
|
|
|
|
|
|
changed = False
|
|
|
|
|
|
|
|
end_state = existing
|
|
|
|
|
|
|
|
commands = []
|
|
|
|
commands = []
|
|
|
|
|
|
|
|
|
|
|
|
if state == 'absent':
|
|
|
|
if state == 'absent':
|
|
|
|
if existing:
|
|
|
|
if existing:
|
|
|
|
command = "no snmp-server community {0}".format(community)
|
|
|
|
command = "no snmp-server community {0}".format(community)
|
|
|
|
commands.append(command)
|
|
|
|
commands.append(command)
|
|
|
|
cmds = flatten_list(commands)
|
|
|
|
|
|
|
|
elif state == 'present':
|
|
|
|
elif state == 'present':
|
|
|
|
if delta:
|
|
|
|
if delta:
|
|
|
|
command = config_snmp_community(dict(delta), community)
|
|
|
|
command = config_snmp_community(dict(delta), community)
|
|
|
|
commands.append(command)
|
|
|
|
commands.append(command)
|
|
|
|
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_snmp_community(module, community)
|
|
|
|
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['end_state'] = end_state
|
|
|
|
|
|
|
|
results['updates'] = cmds
|
|
|
|
|
|
|
|
results['changed'] = changed
|
|
|
|
|
|
|
|
results['warnings'] = warnings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exit_json(**results)
|
|
|
|
module.exit_json(**results)
|
|
|
|
|
|
|
|
|
|
|
|