Debian Codegraph @

ansible_collections/cisco/aci/tests/integration/targets/aci_snmp_client/tasks/main.yml

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2021, Tim Cragg (@timcragg)
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 - name: Test that we have an ACI APIC host, ACI username and ACI password
7 ansible.builtin.fail:
8 msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
9 when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
10
11 # GET Credentials from the inventory
12 - name: Set vars
13 ansible.builtin.set_fact:
14 aci_info: &aci_info
15 host: "{{ aci_hostname }}"
16 username: "{{ aci_username }}"
17 password: "{{ aci_password }}"
18 validate_certs: '{{ aci_validate_certs | default(false) }}'
19 use_ssl: '{{ aci_use_ssl | default(true) }}'
20 use_proxy: '{{ aci_use_proxy | default(true) }}'
21 output_level: debug
22
23 # CLEAN ENVIRONMENT
24 - name: Remove ansible_snmp_client_group if it already exists
25 cisco.aci.aci_snmp_policy:
26 <<: *aci_info
27 name: ansible_snmp_policy
28 state: absent
29
30 # ADD snmp policy
31 - name: Add snmp policy
32 cisco.aci.aci_snmp_policy:
33 <<: *aci_info
34 name: ansible_snmp_policy
35 admin_state: enabled
36 state: present
37
38 # ADD snmp client group
39 - name: Add snmp client group
40 cisco.aci.aci_snmp_client_group:
41 <<: *aci_info
42 policy: ansible_snmp_policy
43 client_group: ansible_snmp_client_group
44 mgmt_epg: oob-default
45 state: present
46
47 # ADD snmp client
48 - name: Add snmp client
49 cisco.aci.aci_snmp_client:
50 <<: *aci_info
51 policy: ansible_snmp_policy
52 client_group: ansible_snmp_client_group
53 address: 10.20.30.0/24
54 client_name: snmp_client_name
55 state: present
56 register: add_snmp_client
57
58 - name: Verify that ansible_snmp_client has been created with correct attributes
59 ansible.builtin.assert:
60 that:
61 - add_snmp_client.current.0.snmpClientP.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy/clgrp-ansible_snmp_client_group/client-[10.20.30.0/24]"
62 - add_snmp_client.current.0.snmpClientP.attributes.addr == "10.20.30.0/24"
63 - add_snmp_client.current.0.snmpClientP.attributes.name == "snmp_client_name"
64 - add_snmp_client.current.0.snmpClientP.attributes.annotation == 'orchestrator:ansible'
65
66 # ADD snmp client again to check idempotency
67 - name: Add snmp client again
68 cisco.aci.aci_snmp_client:
69 <<: *aci_info
70 policy: ansible_snmp_policy
71 client_group: ansible_snmp_client_group
72 address: 10.20.30.0/24
73 client_name: snmp_client_name
74 state: present
75 register: add_snmp_client_again
76
77 - name: Verify that add_snmp_client_group_again stays the same
78 ansible.builtin.assert:
79 that:
80 - add_snmp_client_again is not changed
81
82 # MODIFY snmp client
83 - name: Update snmp client
84 cisco.aci.aci_snmp_client:
85 <<: *aci_info
86 policy: ansible_snmp_policy
87 client_group: ansible_snmp_client_group
88 address: 10.20.30.0/24
89 client_name: new_snmp_client_name
90 state: present
91 register: update_snmp_client
92
93 - name: Verify that ansible_snmp_client_group has been updated with correct attributes
94 ansible.builtin.assert:
95 that:
96 - update_snmp_client is changed
97 - update_snmp_client.current.0.snmpClientP.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy/clgrp-ansible_snmp_client_group/client-[10.20.30.0/24]"
98 - update_snmp_client.current.0.snmpClientP.attributes.addr == "10.20.30.0/24"
99 - update_snmp_client.current.0.snmpClientP.attributes.name == "new_snmp_client_name"
100
101 # QUERY snmp client
102 - name: Query snmp client
103 cisco.aci.aci_snmp_client:
104 <<: *aci_info
105 policy: ansible_snmp_policy
106 client_group: ansible_snmp_client_group
107 address: 10.20.30.0/24
108 state: query
109 register: query_snmp_client
110
111 - name: Verify the attributes under query_snmp_client
112 ansible.builtin.assert:
113 that:
114 - query_snmp_client is not changed
115 - query_snmp_client.current.0.snmpClientP.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy/clgrp-ansible_snmp_client_group/client-[10.20.30.0/24]"
116 - query_snmp_client.current.0.snmpClientP.attributes.addr == "10.20.30.0/24"
117 - query_snmp_client.current.0.snmpClientP.attributes.name == "new_snmp_client_name"
118
119 - name: Query all snmp client
120 cisco.aci.aci_snmp_client:
121 <<: *aci_info
122 state: query
123 register: query_snmp_client_all
124
125 - name: Verify query_snmp_client_all
126 ansible.builtin.assert:
127 that:
128 - query_snmp_client_all is not changed
129
130 # DELETE snmp client group
131 - name: Remove the snmp client
132 cisco.aci.aci_snmp_client:
133 <<: *aci_info
134 policy: ansible_snmp_policy
135 client_group: ansible_snmp_client_group
136 address: 10.20.30.0/24
137 state: absent
138 register: remove_snmp_client
139
140 - name: Verify remove_snmp_client
141 ansible.builtin.assert:
142 that:
143 - remove_snmp_client is changed
144 - remove_snmp_client.previous.0.snmpClientP.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy/clgrp-ansible_snmp_client_group/client-[10.20.30.0/24]"
145 - remove_snmp_client.previous.0.snmpClientP.attributes.addr == "10.20.30.0/24"
146
147 # DELETE snmp policy
148 - name: Remove the snmp policy
149 cisco.aci.aci_snmp_policy:
150 <<: *aci_info
151 name: ansible_snmp_policy
152 state: absent
153
154 # DELETE snmp client group
155 - name: Remove the snmp client group
156 cisco.aci.aci_snmp_client_group:
157 <<: *aci_info
158 policy: ansible_snmp_policy
159 client_group: ansible_snmp_client_group
160 state: absent