| 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_firmware_policy: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_firmware_policy |
| 19 |
- test_firmware_policy_2 |
| 20 |
- test_firmware_policy_validate |
| 21 |
- test_firmware_policy_drives_only |
| 22 |
- test_firmware_policy_no_exclusions |
| 23 |
|
| 24 |
- name: Create firmware policy - check-mode |
| 25 |
cisco.intersight.intersight_firmware_policy: |
| 26 |
<<: *api_info |
| 27 |
name: test_firmware_policy |
| 28 |
description: "Test firmware policy description" |
| 29 |
target_platform: "Standalone" |
| 30 |
model_bundle_combo: |
| 31 |
- model_family: "UCSC-C220-M5" |
| 32 |
bundle_version: "4.3(2.250037)" |
| 33 |
- model_family: "UCSC-C220-M4" |
| 34 |
bundle_version: "4.1(2m)" |
| 35 |
tags: |
| 36 |
- Key: "Site" |
| 37 |
Value: "Test" |
| 38 |
check_mode: true |
| 39 |
register: creation_res_check_mode |
| 40 |
|
| 41 |
- name: Verify firmware policy was not created - check-mode |
| 42 |
ansible.builtin.assert: |
| 43 |
that: |
| 44 |
- creation_res_check_mode is changed |
| 45 |
- creation_res_check_mode.api_response == {} |
| 46 |
|
| 47 |
- name: Create firmware policy |
| 48 |
cisco.intersight.intersight_firmware_policy: |
| 49 |
<<: *api_info |
| 50 |
name: test_firmware_policy |
| 51 |
description: "Test firmware policy description" |
| 52 |
target_platform: "Standalone" |
| 53 |
model_bundle_combo: |
| 54 |
- model_family: "UCSC-C220-M5" |
| 55 |
bundle_version: "4.3(2.250037)" |
| 56 |
- model_family: "UCSC-C220-M4" |
| 57 |
bundle_version: "4.1(2m)" |
| 58 |
tags: |
| 59 |
- Key: "Site" |
| 60 |
Value: "Test" |
| 61 |
register: creation_res |
| 62 |
|
| 63 |
- name: Fetch info after creation |
| 64 |
cisco.intersight.intersight_firmware_policy_info: |
| 65 |
<<: *api_info |
| 66 |
name: test_firmware_policy |
| 67 |
register: creation_info_res |
| 68 |
|
| 69 |
- name: Verify firmware policy creation by info |
| 70 |
ansible.builtin.assert: |
| 71 |
that: |
| 72 |
- creation_res.changed |
| 73 |
- creation_info_res.api_response[0].Name == 'test_firmware_policy' |
| 74 |
- creation_info_res.api_response[0].TargetPlatform == "Standalone" |
| 75 |
- creation_info_res.api_response[0].ModelBundleCombo | length == 2 |
| 76 |
- creation_info_res.api_response[0].ModelBundleCombo[0].ModelFamily == "UCSC-C220-M5" |
| 77 |
- creation_info_res.api_response[0].ModelBundleCombo[0].BundleVersion == "4.3(2.250037)" |
| 78 |
|
| 79 |
- name: Verify firmware policy creation response aligns with info response |
| 80 |
ansible.builtin.assert: |
| 81 |
that: |
| 82 |
- creation_res.api_response.Name == creation_info_res.api_response[0].Name |
| 83 |
- creation_res.api_response.TargetPlatform == creation_info_res.api_response[0].TargetPlatform |
| 84 |
- creation_res.api_response.ModelBundleCombo == creation_info_res.api_response[0].ModelBundleCombo |
| 85 |
|
| 86 |
- name: Create firmware policy (idempotency check) |
| 87 |
cisco.intersight.intersight_firmware_policy: |
| 88 |
<<: *api_info |
| 89 |
name: test_firmware_policy |
| 90 |
description: "Test firmware policy description" |
| 91 |
target_platform: "Standalone" |
| 92 |
model_bundle_combo: |
| 93 |
- model_family: "UCSC-C220-M5" |
| 94 |
bundle_version: "4.3(2.250037)" |
| 95 |
- model_family: "UCSC-C220-M4" |
| 96 |
bundle_version: "4.1(2m)" |
| 97 |
tags: |
| 98 |
- Key: "Site" |
| 99 |
Value: "Test" |
| 100 |
register: creation_res_ide |
| 101 |
|
| 102 |
- name: Verify firmware policy creation (idempotency check) |
| 103 |
ansible.builtin.assert: |
| 104 |
that: |
| 105 |
- not creation_res_ide.changed |
| 106 |
|
| 107 |
- name: Validate failure due to missing target_platform |
| 108 |
cisco.intersight.intersight_firmware_policy: |
| 109 |
<<: *api_info |
| 110 |
name: test_firmware_policy_validate |
| 111 |
description: "Test policy description" |
| 112 |
state: present |
| 113 |
register: failure_res |
| 114 |
failed_when: |
| 115 |
- "'state is present but all of the following are missing: target_platform, model_bundle_combo' not in failure_res.msg" |
| 116 |
|
| 117 |
- name: Create firmware policy with excluded components |
| 118 |
cisco.intersight.intersight_firmware_policy: |
| 119 |
<<: *api_info |
| 120 |
name: test_firmware_policy_2 |
| 121 |
description: "Test firmware policy with exclusions" |
| 122 |
target_platform: "Standalone" |
| 123 |
model_bundle_combo: |
| 124 |
- model_family: "UCSC-C220-M7" |
| 125 |
bundle_version: "4.3(4.242038)" |
| 126 |
exclude_drives: true |
| 127 |
exclude_storage_controllers: true |
| 128 |
register: creation_res_b |
| 129 |
|
| 130 |
- name: Verify firmware policy with excluded components |
| 131 |
ansible.builtin.assert: |
| 132 |
that: |
| 133 |
- creation_res_b.changed |
| 134 |
- creation_res_b.api_response.Name == 'test_firmware_policy_2' |
| 135 |
- creation_res_b.api_response.ExcludeComponentList | length == 2 |
| 136 |
- '"local-disk" in creation_res_b.api_response.ExcludeComponentList' |
| 137 |
- '"storage-controller" in creation_res_b.api_response.ExcludeComponentList' |
| 138 |
|
| 139 |
- name: Fetch all firmware policies under the organization |
| 140 |
cisco.intersight.intersight_firmware_policy_info: |
| 141 |
<<: *api_info |
| 142 |
register: creation_info_res_b |
| 143 |
|
| 144 |
- name: Check that there are at least 2 firmware policies under this organization |
| 145 |
ansible.builtin.assert: |
| 146 |
that: |
| 147 |
- creation_info_res_b.api_response | length > 1 |
| 148 |
|
| 149 |
- name: Create firmware policy with only exclude_drives set |
| 150 |
cisco.intersight.intersight_firmware_policy: |
| 151 |
<<: *api_info |
| 152 |
name: test_firmware_policy_drives_only |
| 153 |
description: "Test firmware policy excluding only drives" |
| 154 |
target_platform: "FIAttached" |
| 155 |
model_bundle_combo: |
| 156 |
- model_family: "UCSC-C220-M5" |
| 157 |
bundle_version: "4.3(2.250037)" |
| 158 |
exclude_drives: true |
| 159 |
register: creation_res_drives_only |
| 160 |
|
| 161 |
- name: Verify firmware policy with only drives excluded |
| 162 |
ansible.builtin.assert: |
| 163 |
that: |
| 164 |
- creation_res_drives_only.changed |
| 165 |
- creation_res_drives_only.api_response.ExcludeComponentList | length == 1 |
| 166 |
- '"local-disk" in creation_res_drives_only.api_response.ExcludeComponentList' |
| 167 |
- '"storage-controller" not in creation_res_drives_only.api_response.ExcludeComponentList' |
| 168 |
|
| 169 |
- name: Create firmware policy with no exclusions |
| 170 |
cisco.intersight.intersight_firmware_policy: |
| 171 |
<<: *api_info |
| 172 |
name: test_firmware_policy_no_exclusions |
| 173 |
description: "Test firmware policy with no exclusions" |
| 174 |
target_platform: "Standalone" |
| 175 |
model_bundle_combo: |
| 176 |
- model_family: "UCSC-C220-M4" |
| 177 |
bundle_version: "4.1(2m)" |
| 178 |
register: creation_res_no_exclusions |
| 179 |
|
| 180 |
- name: Verify firmware policy with no exclusions |
| 181 |
ansible.builtin.assert: |
| 182 |
that: |
| 183 |
- creation_res_no_exclusions.changed |
| 184 |
- creation_res_no_exclusions.api_response.ExcludeComponentList is none or creation_res_no_exclusions.api_response.ExcludeComponentList == [] or creation_res_no_exclusions.api_response.ExcludeComponentList is not defined |
| 185 |
|
| 186 |
- name: Update firmware policy by adding exclude components |
| 187 |
cisco.intersight.intersight_firmware_policy: |
| 188 |
<<: *api_info |
| 189 |
name: test_firmware_policy |
| 190 |
description: "Test firmware policy description - updated" |
| 191 |
target_platform: "Standalone" |
| 192 |
model_bundle_combo: |
| 193 |
- model_family: "UCSC-C220-M5" |
| 194 |
bundle_version: "4.3(2.250037)" |
| 195 |
- model_family: "UCSC-C220-M4" |
| 196 |
bundle_version: "4.1(2m)" |
| 197 |
exclude_drives: true |
| 198 |
tags: |
| 199 |
- Key: "Site" |
| 200 |
Value: "Test" |
| 201 |
register: update_res |
| 202 |
|
| 203 |
# Need to fetch info after update as intersight api won't return the updated exclude list as part of the update api. |
| 204 |
- name: Fetch info after update |
| 205 |
cisco.intersight.intersight_firmware_policy_info: |
| 206 |
<<: *api_info |
| 207 |
name: test_firmware_policy |
| 208 |
register: update_info_res |
| 209 |
|
| 210 |
- name: Verify firmware policy update |
| 211 |
ansible.builtin.assert: |
| 212 |
that: |
| 213 |
- update_info_res.api_response[0].ExcludeComponentList | length == 1 |
| 214 |
- '"local-disk" in update_info_res.api_response[0].ExcludeComponentList' |
| 215 |
|
| 216 |
always: |
| 217 |
- name: Remove firmware policies |
| 218 |
cisco.intersight.intersight_firmware_policy: |
| 219 |
<<: *api_info |
| 220 |
name: "{{ item }}" |
| 221 |
state: absent |
| 222 |
loop: |
| 223 |
- test_firmware_policy |
| 224 |
- test_firmware_policy_2 |
| 225 |
- test_firmware_policy_validate |
| 226 |
- test_firmware_policy_drives_only |
| 227 |
- test_firmware_policy_no_exclusions |