mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-19 23:00:22 -07:00
Revert "Bring nxos_snmp_host in line"
This reverts commit43247c8dfe
. Revert "Bring nxos_snmp_community in line" This reverts commit0df77408d7
. Revert "Clean up nxos_snmp_contact & nxos_snmp_location" This reverts commit9e4cdd2fce
. I should probably not be up this early
This commit is contained in:
parent
43247c8dfe
commit
ae6d27fa29
4 changed files with 200 additions and 100 deletions
|
@ -66,7 +66,7 @@ commands:
|
|||
|
||||
import re
|
||||
|
||||
from ansible.module_utils.nxos import 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.basic import AnsibleModule
|
||||
|
||||
|
@ -77,7 +77,7 @@ def execute_show_command(command, module):
|
|||
'output': 'text',
|
||||
}
|
||||
|
||||
return run_commands(module, command)
|
||||
return run_commands(module, [command])
|
||||
|
||||
|
||||
def flatten_list(command_lists):
|
||||
|
@ -92,12 +92,17 @@ def flatten_list(command_lists):
|
|||
|
||||
def get_snmp_contact(module):
|
||||
contact = {}
|
||||
contact_regex = r'^\s*snmp-server\scontact\s(?P<contact>.+)$'
|
||||
contact_regex = '.*snmp-server\scontact\s(?P<contact>\S+).*'
|
||||
command = 'show run snmp'
|
||||
|
||||
body = execute_show_command('show run snmp', module)[0]
|
||||
match_contact = re.search(contact_regex, body, re.M)
|
||||
if match_contact:
|
||||
contact['contact'] = match_contact.group("contact")
|
||||
body = execute_show_command(command, module)[0]
|
||||
|
||||
try:
|
||||
match_contact = re.match(contact_regex, body, re.DOTALL)
|
||||
group_contact = match_contact.groupdict()
|
||||
contact['contact'] = group_contact["contact"]
|
||||
except AttributeError:
|
||||
contact = {}
|
||||
|
||||
return contact
|
||||
|
||||
|
@ -105,21 +110,25 @@ def get_snmp_contact(module):
|
|||
def main():
|
||||
argument_spec = dict(
|
||||
contact=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 = {'changed': False, 'commands': [], 'warnings': warnings}
|
||||
|
||||
|
||||
contact = module.params['contact']
|
||||
state = module.params['state']
|
||||
|
||||
existing = get_snmp_contact(module)
|
||||
proposed = dict(contact=contact)
|
||||
commands = []
|
||||
|
||||
if state == 'absent':
|
||||
|
@ -131,12 +140,11 @@ def main():
|
|||
|
||||
cmds = flatten_list(commands)
|
||||
if cmds:
|
||||
results['changed'] = True
|
||||
if not module.check_mode:
|
||||
load_config(module, cmds)
|
||||
|
||||
if 'configure' in cmds:
|
||||
cmds.pop(0)
|
||||
results['changed'] = True
|
||||
results['commands'] = cmds
|
||||
|
||||
module.exit_json(**results)
|
||||
|
@ -144,3 +152,4 @@ def main():
|
|||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue