Debian Codegraph @

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

raw symbols SCIP
1 # Test code for the ACI modules
2 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[email protected]>
3 # Copyright: (c) 2023, Tim Cragg (@timcragg) <[email protected]>
4
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 - name: Test that we have an ACI APIC host, ACI username and ACI password
8 ansible.builtin.fail:
9 msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
10 when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
11
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 the ansible_tenant
25 cisco.aci.aci_tenant: &aci_tenant_absent
26 <<: *aci_info
27 tenant: ansible_tenant
28 state: absent
29
30 - name: Verify Cloud and Non-Cloud Sites in use.
31 ansible.builtin.include_tasks: ../../../../../../integration/targets/aci_cloud_provider/tasks/main.yml
32
33 - name: Execute tasks only for non-cloud sites
34 when: query_cloud.current == [] # This condition will execute only non-cloud sites
35 block: # block specifies execution of tasks within, based on conditions
36 - name: Add a new tenant
37 cisco.aci.aci_tenant: &aci_tenant_present
38 <<: *aci_info
39 tenant: ansible_tenant
40 description: Ansible tenant
41 state: present
42
43 - name: Add a match rule profile (check_mode)
44 cisco.aci.aci_match_rule: &aci_match_rule_present
45 <<: *aci_info
46 tenant: ansible_tenant
47 match_rule: ansible_match_rule_1
48 description: match rule profile 1 for ansible_tenant tenant
49 state: present
50 check_mode: true
51 register: cm_add_match_rule
52
53 - name: Add a match rule profile (normal_mode)
54 cisco.aci.aci_match_rule:
55 <<: *aci_match_rule_present
56 register: nm_add_match_rule
57
58 - name: Add the first match rule profile again - testing idempotency
59 cisco.aci.aci_match_rule:
60 <<: *aci_match_rule_present
61 register: nm_add_match_rule_idempotency
62
63 - name: Add a second match rule profile (normal_mode)
64 cisco.aci.aci_match_rule:
65 <<: *aci_info
66 tenant: ansible_tenant
67 match_rule: ansible_match_rule_2
68 description: match rule profile 2 for ansible_tenant tenant
69 state: present
70 register: nm_add_match_rule_2
71
72 - name: Asserts for match rule profiles creation tasks
73 ansible.builtin.assert:
74 that:
75 - cm_add_match_rule is changed
76 - cm_add_match_rule.previous == []
77 - cm_add_match_rule.current == []
78 - nm_add_match_rule is changed
79 - nm_add_match_rule.current.0.rtctrlSubjP.attributes.name == "ansible_match_rule_1"
80 - nm_add_match_rule_idempotency is not changed
81 - nm_add_match_rule_2 is changed
82 - nm_add_match_rule_2.previous == []
83 - nm_add_match_rule_2.current.0.rtctrlSubjP.attributes.name == "ansible_match_rule_2"
84
85 - name: Query all match rule profiles
86 cisco.aci.aci_match_rule:
87 <<: *aci_info
88 state: query
89 register: query_all_match_rule
90
91 - name: Query ansible_match_rule_1
92 cisco.aci.aci_match_rule:
93 <<: *aci_match_rule_present
94 state: query
95 register: query_ansible_match_rule_1
96
97 - name: Asserts query tasks
98 ansible.builtin.assert:
99 that:
100 - query_all_match_rule is not changed
101 - query_all_match_rule.current|length >= 2
102 - query_ansible_match_rule_1 is not changed
103 - query_ansible_match_rule_1.current.0.rtctrlSubjP.attributes.name == "ansible_match_rule_1"
104
105 - name: Remove match rule profile for l3out (check_mode)
106 cisco.aci.aci_match_rule: &match_rule_absent
107 <<: *aci_match_rule_present
108 state: absent
109 check_mode: true
110 register: cm_remove_match_rule
111
112 - name: Remove match rule profile for l3out (normal_mode)
113 cisco.aci.aci_match_rule:
114 <<: *match_rule_absent
115 register: nm_remove_match_rule
116
117 - name: Remove match rule profile for l3out again - testing previous Removal
118 cisco.aci.aci_match_rule:
119 <<: *match_rule_absent
120 register: nm_remove_match_rule_idempotency
121
122 - name: Asserts deletion tasks
123 ansible.builtin.assert:
124 that:
125 - cm_remove_match_rule is changed
126 - cm_remove_match_rule.proposed == {}
127 - nm_remove_match_rule is changed
128 - nm_remove_match_rule.previous != []
129 - nm_remove_match_rule.method == "DELETE"
130 - nm_remove_match_rule_idempotency is not changed
131 - nm_remove_match_rule_idempotency.previous == []
132
133 - name: Remove the ansible_tenant - cleanup before ending tests
134 cisco.aci.aci_tenant:
135 <<: *aci_tenant_present
136 state: absent