Debian Codegraph @

ansible_collections/cisco/aci/tests/integration/targets/aci_snmp_policy/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_policy 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 contact: snmp contact
37 location: snmp location
38 description: policy description
39 state: present
40 register: add_snmp_policy
41
42 - name: Verify that ansible_snmp_policy has been created with correct attributes
43 ansible.builtin.assert:
44 that:
45 - add_snmp_policy.current.0.snmpPol.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy"
46 - add_snmp_policy.current.0.snmpPol.attributes.name == "ansible_snmp_policy"
47 - add_snmp_policy.current.0.snmpPol.attributes.contact == "snmp contact"
48 - add_snmp_policy.current.0.snmpPol.attributes.loc == "snmp location"
49 - add_snmp_policy.current.0.snmpPol.attributes.adminSt == "enabled"
50 - add_snmp_policy.current.0.snmpPol.attributes.descr == "policy description"
51 - add_snmp_policy.current.0.snmpPol.attributes.annotation == 'orchestrator:ansible'
52
53 # ADD snmp policy again to check idempotency
54 - name: Add snmp policy
55 cisco.aci.aci_snmp_policy:
56 <<: *aci_info
57 name: ansible_snmp_policy
58 admin_state: enabled
59 contact: snmp contact
60 location: snmp location
61 description: policy description
62 state: present
63 register: add_snmp_policy_again
64
65 - name: Verify that ansible_snmp_policy stays the same
66 ansible.builtin.assert:
67 that:
68 - add_snmp_policy_again is not changed
69
70 # MODIFY snmp policy
71 - name: Update snmp policy
72 cisco.aci.aci_snmp_policy:
73 <<: *aci_info
74 name: ansible_snmp_policy
75 admin_state: disabled
76 contact: new snmp contact
77 location: new snmp location
78 description: new policy description
79 state: present
80 register: update_snmp_policy
81
82 - name: Verify that ansible_snmp_policy has been updated with correct attributes
83 ansible.builtin.assert:
84 that:
85 - update_snmp_policy.current.0.snmpPol.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy"
86 - update_snmp_policy.current.0.snmpPol.attributes.name == "ansible_snmp_policy"
87 - update_snmp_policy.current.0.snmpPol.attributes.contact == "new snmp contact"
88 - update_snmp_policy.current.0.snmpPol.attributes.loc == "new snmp location"
89 - update_snmp_policy.current.0.snmpPol.attributes.adminSt == "disabled"
90 - update_snmp_policy.current.0.snmpPol.attributes.descr == "new policy description"
91
92 # QUERY snmp policy
93 - name: Query snmp policy
94 cisco.aci.aci_snmp_policy:
95 <<: *aci_info
96 name: ansible_snmp_policy
97 state: query
98 register: query_snmp_policy
99
100 - name: Verify the attributes under query_snmp_policy
101 ansible.builtin.assert:
102 that:
103 - query_snmp_policy is not changed
104 - query_snmp_policy.current.0.snmpPol.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy"
105 - query_snmp_policy.current.0.snmpPol.attributes.name == "ansible_snmp_policy"
106 - query_snmp_policy.current.0.snmpPol.attributes.contact == "new snmp contact"
107 - query_snmp_policy.current.0.snmpPol.attributes.loc == "new snmp location"
108 - query_snmp_policy.current.0.snmpPol.attributes.adminSt == "disabled"
109 - query_snmp_policy.current.0.snmpPol.attributes.descr == "new policy description"
110
111 - name: Query all snmp policies
112 cisco.aci.aci_snmp_policy:
113 <<: *aci_info
114 state: query
115 register: query_snmp_policy_all
116
117 - name: Verify query_snmp_policy_all
118 ansible.builtin.assert:
119 that:
120 - query_snmp_policy_all is not changed
121
122 # DELETE snmp policy
123 - name: Remove the snmp policy
124 cisco.aci.aci_snmp_policy:
125 <<: *aci_info
126 name: ansible_snmp_policy
127 state: absent
128 register: remove_snmp_policy
129
130 - name: Verify remove_snmp_policy
131 ansible.builtin.assert:
132 that:
133 - remove_snmp_policy is changed
134 - remove_snmp_policy.previous.0.snmpPol.attributes.dn == "uni/fabric/snmppol-ansible_snmp_policy"
135 - remove_snmp_policy.previous.0.snmpPol.attributes.name == "ansible_snmp_policy"