I need to update (standardize) the SNMP trap receivers throughout the network. Given that i'm running Cisco NX OS on the 3500 platform I can't delete the old SNMP trap receiver configuration without specifying the hosts. So I need to run a command and then parse the hosts from it. I'd like to then use the hosts in the returned output to delete the trap receivers before adding the new correct receivers.
---
- name: Update the SNMP information on the network
hosts: lab
gather_facts: no
connection: local
vars:
trapdests: []
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 }}"
- name: snmp update
ios_config:
src: "./configs/snmp.conf"
provider: "{{ ios_provider }}"
match: none
before: "default snmp-server"
- debug: msg="{{command_output.stdout_lines}}"
< PLAY [Update the SNMP information on the network] >
---------------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
_______________________
< TASK [test nxos snmp] >
-----------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
[WARNING]: argument host has been deprecated and will be removed in a future version
changed: [lab-xxx-xxx-xxxxx]
changed: [10.70.253.249]
_______________________________
< TASK [get current snmp hosts] >
-------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [10.70.253.249]
ok: [lab-xxxx-xxx-xxxxx]
____________________
< TASK [snmp update] >
--------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
changed: [10.70.253.249]
changed: [lab-xxx-xxx-xxxx1x]
______________
< TASK [debug] >
--------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
ok: [10.70.253.249] => {
"msg": [
[
"Source interface: mgmt0-------------------------------------------------------------------",
"Host Port Version Level Type SecName ",
"-------------------------------------------------------------------",
"10.15.24.118 162 v2c noauth trap xxxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"10.30.130.131 162 v2c noauth trap xxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"10.50.74.49 162 v2c noauth trap xxxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"10.50.74.50 162 v2c noauth trap xxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"1.1.1.1 162 v2c noauth trap TESTING ",
"-------------------------------------------------------------------"
]
]
}
ok: [lab-db9-eng-acc01x] => {
"msg": [
[
"-------------------------------------------------------------------",
"Host Port Version Level Type SecName ",
"-------------------------------------------------------------------",
"10.50.74.38 162 v2c noauth trap xxxxx ",
"-------------------------------------------------------------------",
"10.50.32.23 162 v2c noauth trap xxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"10.50.74.50 162 v2c noauth trap xxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"10.50.74.49 162 v2c noauth trap xxxxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"10.30.130.131 162 v2c noauth trap xxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"10.15.24.118 162 v2c noauth trap xxxx ",
"Use VRF: management",
"-------------------------------------------------------------------",
"1.1.1.1 162 v2c noauth trap TESTING ",
"-------------------------------------------------------------------"
]
]
}
____________
< PLAY RECAP >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
10.70.253.249 : ok=4 changed=2 unreachable=0 failed=0
lab-xxx-xxx-xxx01x : ok=4 changed=2 unreachable=0 failed=0