| 1 |
--- |
| 2 |
- block: |
| 3 |
- name: Define anchor for Intersight API login info |
| 4 |
ansible.builtin.set_fact: |
| 5 |
api_info: &api_info |
| 6 |
api_private_key: "{{ api_private_key }}" |
| 7 |
api_key_id: "{{ api_key_id }}" |
| 8 |
api_uri: "{{ api_uri | default(omit) }}" |
| 9 |
validate_certs: "{{ validate_certs | default(omit) }}" |
| 10 |
organization: "{{ organization }}" |
| 11 |
|
| 12 |
- name: Make sure Env is clean |
| 13 |
cisco.intersight.intersight_multicast_policy: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_multicast_policy |
| 19 |
- test_multicast_policy_2 |
| 20 |
- test_multicast_policy_3 |
| 21 |
|
| 22 |
- name: Create multicast policy - check-mode |
| 23 |
cisco.intersight.intersight_multicast_policy: |
| 24 |
<<: *api_info |
| 25 |
name: test_multicast_policy |
| 26 |
description: "Test multicast policy description" |
| 27 |
tags: |
| 28 |
- Key: Site |
| 29 |
Value: Test |
| 30 |
- Key: Site2 |
| 31 |
Value: Test2 |
| 32 |
querier_state: "Enabled" |
| 33 |
snooping_state: "Enabled" |
| 34 |
querier_ip_address: "192.168.1.1" |
| 35 |
querier_ip_address_peer: "192.168.1.2" |
| 36 |
src_ip_proxy: "Enabled" |
| 37 |
check_mode: true |
| 38 |
register: creation_res_check_mode |
| 39 |
|
| 40 |
- name: Verify multicast policy was not created - check-mode |
| 41 |
ansible.builtin.assert: |
| 42 |
that: |
| 43 |
- creation_res_check_mode is changed |
| 44 |
- creation_res_check_mode.api_response == {} |
| 45 |
|
| 46 |
- name: Create multicast policy |
| 47 |
cisco.intersight.intersight_multicast_policy: |
| 48 |
<<: *api_info |
| 49 |
name: test_multicast_policy |
| 50 |
description: "Test multicast policy description" |
| 51 |
tags: |
| 52 |
- Key: Site |
| 53 |
Value: Test |
| 54 |
- Key: Site2 |
| 55 |
Value: Test2 |
| 56 |
querier_state: "Enabled" |
| 57 |
snooping_state: "Enabled" |
| 58 |
querier_ip_address: "192.168.1.1" |
| 59 |
querier_ip_address_peer: "192.168.1.2" |
| 60 |
src_ip_proxy: "Enabled" |
| 61 |
register: creation_res |
| 62 |
|
| 63 |
- name: Fetch info after creation |
| 64 |
cisco.intersight.intersight_multicast_policy_info: |
| 65 |
<<: *api_info |
| 66 |
name: test_multicast_policy |
| 67 |
register: creation_info_res |
| 68 |
|
| 69 |
- name: Verify multicast policy creation by info |
| 70 |
ansible.builtin.assert: |
| 71 |
that: |
| 72 |
- creation_res.changed |
| 73 |
- creation_info_res.api_response[0].Name == 'test_multicast_policy' |
| 74 |
- creation_info_res.api_response[0].QuerierState == 'Enabled' |
| 75 |
- creation_info_res.api_response[0].SnoopingState == 'Enabled' |
| 76 |
- creation_info_res.api_response[0].QuerierIpAddress == '192.168.1.1' |
| 77 |
- creation_info_res.api_response[0].QuerierIpAddressPeer == '192.168.1.2' |
| 78 |
- creation_info_res.api_response[0].SrcIpProxy == 'Enabled' |
| 79 |
|
| 80 |
- name: Verify multicast policy creation response aligns with info response |
| 81 |
ansible.builtin.assert: |
| 82 |
that: |
| 83 |
- creation_res.api_response.Name == creation_info_res.api_response[0].Name |
| 84 |
- creation_res.api_response.QuerierState == creation_info_res.api_response[0].QuerierState |
| 85 |
- creation_res.api_response.SnoopingState == creation_info_res.api_response[0].SnoopingState |
| 86 |
|
| 87 |
- name: Create multicast policy (idempotency check) |
| 88 |
cisco.intersight.intersight_multicast_policy: |
| 89 |
<<: *api_info |
| 90 |
name: test_multicast_policy |
| 91 |
description: "Test multicast policy description" |
| 92 |
tags: |
| 93 |
- Key: Site |
| 94 |
Value: Test |
| 95 |
- Key: Site2 |
| 96 |
Value: Test2 |
| 97 |
querier_state: "Enabled" |
| 98 |
snooping_state: "Enabled" |
| 99 |
querier_ip_address: "192.168.1.1" |
| 100 |
querier_ip_address_peer: "192.168.1.2" |
| 101 |
src_ip_proxy: "Enabled" |
| 102 |
register: creation_res_ide |
| 103 |
|
| 104 |
- name: Verify multicast policy creation (idempotency check) |
| 105 |
ansible.builtin.assert: |
| 106 |
that: |
| 107 |
- not creation_res_ide.changed |
| 108 |
|
| 109 |
- name: Change settings on existing multicast policy |
| 110 |
cisco.intersight.intersight_multicast_policy: |
| 111 |
<<: *api_info |
| 112 |
name: test_multicast_policy |
| 113 |
querier_state: "Disabled" |
| 114 |
snooping_state: "Enabled" |
| 115 |
src_ip_proxy: "Disabled" |
| 116 |
register: changed_res |
| 117 |
|
| 118 |
- name: Fetch info after change |
| 119 |
cisco.intersight.intersight_multicast_policy_info: |
| 120 |
<<: *api_info |
| 121 |
name: test_multicast_policy |
| 122 |
register: change_info_res |
| 123 |
|
| 124 |
- name: Verify multicast policy change by info |
| 125 |
ansible.builtin.assert: |
| 126 |
that: |
| 127 |
- changed_res.changed |
| 128 |
- change_info_res.api_response[0].Name == 'test_multicast_policy' |
| 129 |
- change_info_res.api_response[0].QuerierState == 'Disabled' |
| 130 |
- change_info_res.api_response[0].SnoopingState == 'Enabled' |
| 131 |
- change_info_res.api_response[0].SrcIpProxy == 'Disabled' |
| 132 |
|
| 133 |
- name: Create another multicast policy with basic settings |
| 134 |
cisco.intersight.intersight_multicast_policy: |
| 135 |
<<: *api_info |
| 136 |
name: test_multicast_policy_2 |
| 137 |
description: "Test basic multicast policy" |
| 138 |
querier_state: "Disabled" |
| 139 |
snooping_state: "Enabled" |
| 140 |
src_ip_proxy: "Enabled" |
| 141 |
register: creation_res_b |
| 142 |
|
| 143 |
- name: Verify second policy creation |
| 144 |
cisco.intersight.intersight_multicast_policy_info: |
| 145 |
<<: *api_info |
| 146 |
name: test_multicast_policy_2 |
| 147 |
register: creation_info_res_b |
| 148 |
|
| 149 |
- name: Verify second policy has correct basic settings |
| 150 |
ansible.builtin.assert: |
| 151 |
that: |
| 152 |
- creation_info_res_b.api_response[0].QuerierState == 'Disabled' |
| 153 |
- creation_info_res_b.api_response[0].SnoopingState == 'Enabled' |
| 154 |
- creation_info_res_b.api_response[0].SrcIpProxy == 'Enabled' |
| 155 |
|
| 156 |
- name: Test validation rule - try to create invalid policy (Snooping Disabled + Querier Enabled) |
| 157 |
cisco.intersight.intersight_multicast_policy: |
| 158 |
<<: *api_info |
| 159 |
name: test_multicast_policy_3 |
| 160 |
description: "This should fail validation" |
| 161 |
querier_state: "Enabled" |
| 162 |
snooping_state: "Disabled" |
| 163 |
querier_ip_address: "192.168.1.1" |
| 164 |
src_ip_proxy: "Enabled" |
| 165 |
register: validation_test_res |
| 166 |
ignore_errors: true |
| 167 |
|
| 168 |
- name: Verify that invalid configuration was rejected |
| 169 |
ansible.builtin.assert: |
| 170 |
that: |
| 171 |
- validation_test_res.failed |
| 172 |
- "'Invalid configuration' in validation_test_res.msg" |
| 173 |
- "'Snooping Disabled and Querier Enabled' in validation_test_res.msg" |
| 174 |
|
| 175 |
- name: Fetch all multicast policies under selected organization |
| 176 |
cisco.intersight.intersight_multicast_policy_info: |
| 177 |
<<: *api_info |
| 178 |
register: creation_info_res_final |
| 179 |
|
| 180 |
- name: Check that there are at least two multicast policies under this organization |
| 181 |
ansible.builtin.assert: |
| 182 |
that: |
| 183 |
- creation_info_res_final.api_response | length >= 2 |
| 184 |
|
| 185 |
always: |
| 186 |
- name: Remove multicast policies |
| 187 |
cisco.intersight.intersight_multicast_policy: |
| 188 |
<<: *api_info |
| 189 |
name: "{{ item }}" |
| 190 |
state: absent |
| 191 |
loop: |
| 192 |
- test_multicast_policy |
| 193 |
- test_multicast_policy_2 |
| 194 |
- test_multicast_policy_3 |