Hi Ganesh,
I think the first thing I’m trying to do is build a json object with the IP addresses of the currently configured trap receivers. So the first task is as follows:
vars:
trapdests: [] # I want to populate this list with currently configured trap receivers
ios_provider:
username: “{{ user }}”
password: “{{ password }}”
host: “{{ inventory_hostname }}”
tasks:
- name: get current snmp hosts
register: command_output
ios_command:
commands: “show snmp host”
provider: “{{ ios_provider }}”
- debug: msg=“{{command_output.stdout_lines}}”
The next task is to extract the trap receivers from the command output (here is a sample of the command out - from the debug statement above)
ok: [lab-xxx-xx-xxxxx] => {
“msg”: [
[
“-------------------------------------------------------------------”,
"Host Port Version Level Type SecName ",
“-------------------------------------------------------------------”,
"10.50.74.38 162 v2c noauth trap mypub ",
“-------------------------------------------------------------------”,
"10.50.32.23 162 v2c noauth trap mypub ",
“Use VRF: management”,
“-------------------------------------------------------------------”,
"10.50.74.50 162 v2c noauth trap mypub ",
“Use VRF: management”,
“-------------------------------------------------------------------”,
"10.50.74.49 162 v2c noauth trap mypub ",
“Use VRF: management”,
“-------------------------------------------------------------------”,
"10.30.130.131 162 v2c noauth trap mypub ",
“Use VRF: management”,
“-------------------------------------------------------------------”,
"10.15.24.118 162 v2c noauth trap mypub ",
“Use VRF: management”,
“-------------------------------------------------------------------”,
"1.1.1.1 162 v2c noauth trap TESTING ",
“-------------------------------------------------------------------”
]
]
}
So what I’m trying to learn is how to use a regular expression to extract each IP address from this output , update the trapdests list with these addresses, and then use them to do a
no snmp-server traps version 2c mypub
no snmp-server use-vrf management
I hope that makes sense.
Just as a note - a similar approach is take here https://www.netnea.com/cms/2016/10/16/using-ansible-to-fetch-information-from-ios-devices/ , but that approach is on IOS so the command output is very different and I can’t seem to pass a regular expression to the cisco command from within Ansible to even get something similar.
Thanks
Gav