Debian Codegraph @

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

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[email protected]>
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 - name: Set vars
12 ansible.builtin.set_fact:
13 aci_info: &aci_info
14 host: "{{ aci_hostname }}"
15 username: "{{ aci_username }}"
16 password: "{{ aci_password }}"
17 validate_certs: '{{ aci_validate_certs | default(false) }}'
18 use_ssl: '{{ aci_use_ssl | default(true) }}'
19 use_proxy: '{{ aci_use_proxy | default(true) }}'
20 output_level: debug
21
22 # CLEAN ENVIRONMENT
23 - name: Remove the ansible_tenant
24 cisco.aci.aci_tenant: &aci_tenant_absent
25 <<: *aci_info
26 tenant: ansible_tenant
27 state: absent
28
29 - name: Verify Cloud and Non-Cloud Sites in use.
30 ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml
31
32 - name: Execute tasks only for non-cloud sites
33 when: query_cloud.current == [] # This condition will execute only non-cloud sites
34 block: # block specifies execution of tasks within, based on conditions
35 - name: Add a new tenant
36 cisco.aci.aci_tenant: &aci_tenant_present
37 <<: *aci_info
38 tenant: ansible_tenant
39 description: Ansible tenant
40 state: present
41
42 - name: Add a new Keychain policy
43 cisco.aci.aci_keychain_policy:
44 <<: *aci_info
45 tenant: ansible_tenant
46 keychain_policy: ansible_keychain_policy_1
47 description: Keychain policy 1 for ansible_tenant tenant
48 state: present
49
50 - name: Add a Key policy (check_mode)
51 cisco.aci.aci_key_policy: &aci_key_policy_present
52 <<: *aci_info
53 tenant: ansible_tenant
54 keychain_policy: ansible_keychain_policy_1
55 id: 1
56 description: Key policy 1 for ansible_tenant tenant
57 start_time: "2024-01-01 00:00:00"
58 end_time: "2026-01-01 00:00:00"
59 pre_shared_key: my_password
60 state: present
61 check_mode: true
62 register: cm_add_key_policy
63
64 - name: Add a Key policy (normal_mode)
65 cisco.aci.aci_key_policy:
66 <<: *aci_key_policy_present
67 register: nm_add_key_policy
68
69 - name: Add the first Key policy again - testing hidden key authentification
70 cisco.aci.aci_key_policy:
71 <<: *aci_key_policy_present
72 register: nm_add_key_policy_idempotency
73
74 - name: Add a second Key policy (normal_mode)
75 cisco.aci.aci_key_policy:
76 <<: *aci_info
77 tenant: ansible_tenant
78 keychain_policy: ansible_keychain_policy_1
79 id: 2
80 description: Key policy 2 for ansible_tenant tenant
81 state: present
82 register: nm_add_key_policy_2
83
84 - name: Asserts for Key policys creation tasks
85 ansible.builtin.assert:
86 that:
87 - cm_add_key_policy is changed
88 - cm_add_key_policy.previous == []
89 - cm_add_key_policy.current == []
90 - nm_add_key_policy is changed
91 - nm_add_key_policy.current.0.fvKeyPol.attributes.id == "1"
92 - nm_add_key_policy.current.0.fvKeyPol.attributes.startTime == "2024-01-01T00:00:00.000+00:00"
93 - nm_add_key_policy.current.0.fvKeyPol.attributes.endTime == "2026-01-01T00:00:00.000+00:00"
94 - nm_add_key_policy.current.0.fvKeyPol.attributes.preSharedKey is undefined
95 - nm_add_key_policy.proposed.fvKeyPol.attributes.preSharedKey == "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
96 # Idempotency is not supported when pre_shared_key is set
97 - nm_add_key_policy_idempotency is changed
98 - nm_add_key_policy_idempotency.current == nm_add_key_policy_idempotency.previous
99 - nm_add_key_policy_idempotency.current.0.fvKeyPol.attributes.preSharedKey is undefined
100 - nm_add_key_policy_idempotency.previous.0.fvKeyPol.attributes.preSharedKey is undefined
101 - nm_add_key_policy_idempotency.proposed.fvKeyPol.attributes.preSharedKey == "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
102 - nm_add_key_policy_2 is changed
103 - nm_add_key_policy_2.previous == []
104 - nm_add_key_policy_2.current.0.fvKeyPol.attributes.id == "2"
105 - nm_add_key_policy_2.current.0.fvKeyPol.attributes.endTime == "infinite"
106
107 - name: Query all Key policies
108 cisco.aci.aci_key_policy:
109 <<: *aci_info
110 state: query
111 register: query_all_key_policy
112
113 - name: Query ansible_key_policy_1
114 cisco.aci.aci_key_policy:
115 <<: *aci_key_policy_present
116 state: query
117 register: query_ansible_key_policy_1
118
119 - name: Asserts query tasks
120 ansible.builtin.assert:
121 that:
122 - query_all_key_policy is not changed
123 - query_all_key_policy.current|length >= 2
124 - query_ansible_key_policy_1 is not changed
125 - query_ansible_key_policy_1.current.0.fvKeyPol.attributes.id == "1"
126 - query_ansible_key_policy_1.current.0.fvKeyPol.attributes.startTime == "2024-01-01T00:00:00.000+00:00"
127 - query_ansible_key_policy_1.current.0.fvKeyPol.attributes.endTime == "2026-01-01T00:00:00.000+00:00"
128
129 - name: Remove Key policy (check_mode)
130 cisco.aci.aci_key_policy: &key_policy_absent
131 <<: *aci_key_policy_present
132 state: absent
133 check_mode: true
134 register: cm_remove_key_policy
135
136 - name: Remove Key policy (normal_mode)
137 cisco.aci.aci_key_policy:
138 <<: *key_policy_absent
139 register: nm_remove_key_policy
140
141 - name: Remove Key policy - testing idempotency
142 cisco.aci.aci_key_policy:
143 <<: *key_policy_absent
144 register: nm_remove_key_policy_idempotency
145
146 - name: Asserts deletion tasks
147 ansible.builtin.assert:
148 that:
149 - cm_remove_key_policy is changed
150 - cm_remove_key_policy.proposed == {}
151 - nm_remove_key_policy is changed
152 - nm_remove_key_policy.previous != []
153 - nm_remove_key_policy.method == "DELETE"
154 - nm_remove_key_policy_idempotency is not changed
155 - nm_remove_key_policy_idempotency.previous == []
156
157 - name: Remove the ansible_tenant - cleanup before ending tests
158 cisco.aci.aci_tenant:
159 <<: *aci_tenant_present
160 state: absent