| 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 environment is clean |
| 13 |
cisco.intersight.intersight_kvm_policy: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_kvm_policy_enabled |
| 19 |
- test_kvm_policy_disabled |
| 20 |
- test_kvm_policy_custom |
| 21 |
- test_kvm_policy_validation |
| 22 |
|
| 23 |
- name: Create enabled KVM policy with defaults - check-mode |
| 24 |
cisco.intersight.intersight_kvm_policy: |
| 25 |
<<: *api_info |
| 26 |
name: test_kvm_policy_enabled |
| 27 |
description: "Test enabled KVM policy with default settings" |
| 28 |
enabled: true |
| 29 |
tags: |
| 30 |
- Key: Site |
| 31 |
Value: Test |
| 32 |
check_mode: true |
| 33 |
register: enabled_creation_check_mode |
| 34 |
|
| 35 |
- name: Verify enabled KVM policy was not created - check-mode |
| 36 |
ansible.builtin.assert: |
| 37 |
that: |
| 38 |
- enabled_creation_check_mode is changed |
| 39 |
- enabled_creation_check_mode.api_response == {} |
| 40 |
|
| 41 |
- name: Create enabled KVM policy with defaults |
| 42 |
cisco.intersight.intersight_kvm_policy: |
| 43 |
<<: *api_info |
| 44 |
name: test_kvm_policy_enabled |
| 45 |
description: "Test enabled KVM policy with default settings" |
| 46 |
enabled: true |
| 47 |
tags: |
| 48 |
- Key: Site |
| 49 |
Value: Test |
| 50 |
register: enabled_creation |
| 51 |
|
| 52 |
- name: Fetch info after enabled KVM policy creation |
| 53 |
cisco.intersight.intersight_kvm_policy_info: |
| 54 |
<<: *api_info |
| 55 |
name: test_kvm_policy_enabled |
| 56 |
register: enabled_info |
| 57 |
|
| 58 |
- name: Verify enabled KVM policy creation |
| 59 |
ansible.builtin.assert: |
| 60 |
that: |
| 61 |
- enabled_creation.changed |
| 62 |
- enabled_info.api_response[0].Name == 'test_kvm_policy_enabled' |
| 63 |
- enabled_info.api_response[0].Enabled == true |
| 64 |
- enabled_info.api_response[0].MaximumSessions == 4 |
| 65 |
- enabled_info.api_response[0].RemotePort == 2068 |
| 66 |
- enabled_info.api_response[0].EnableVideoEncryption == true |
| 67 |
- enabled_info.api_response[0].EnableLocalServerVideo == true |
| 68 |
- enabled_info.api_response[0].TunneledKvmEnabled == false |
| 69 |
|
| 70 |
- name: Verify enabled KVM policy creation response aligns with info response |
| 71 |
ansible.builtin.assert: |
| 72 |
that: |
| 73 |
- enabled_creation.api_response.Name == enabled_info.api_response[0].Name |
| 74 |
- enabled_creation.api_response.Enabled == enabled_info.api_response[0].Enabled |
| 75 |
- enabled_creation.api_response.MaximumSessions == enabled_info.api_response[0].MaximumSessions |
| 76 |
|
| 77 |
- name: Create enabled KVM policy with defaults (idempotency check) |
| 78 |
cisco.intersight.intersight_kvm_policy: |
| 79 |
<<: *api_info |
| 80 |
name: test_kvm_policy_enabled |
| 81 |
description: "Test enabled KVM policy with default settings" |
| 82 |
enabled: true |
| 83 |
tags: |
| 84 |
- Key: Site |
| 85 |
Value: Test |
| 86 |
register: enabled_creation_ide |
| 87 |
|
| 88 |
- name: Verify enabled KVM policy creation (idempotency check) |
| 89 |
ansible.builtin.assert: |
| 90 |
that: |
| 91 |
- not enabled_creation_ide.changed |
| 92 |
|
| 93 |
- name: Create disabled KVM policy |
| 94 |
cisco.intersight.intersight_kvm_policy: |
| 95 |
<<: *api_info |
| 96 |
name: test_kvm_policy_disabled |
| 97 |
description: "Test disabled KVM policy" |
| 98 |
enabled: false |
| 99 |
tags: |
| 100 |
- Key: Security |
| 101 |
Value: Disabled |
| 102 |
register: disabled_creation |
| 103 |
|
| 104 |
- name: Fetch info after disabled KVM policy creation |
| 105 |
cisco.intersight.intersight_kvm_policy_info: |
| 106 |
<<: *api_info |
| 107 |
name: test_kvm_policy_disabled |
| 108 |
register: disabled_info |
| 109 |
|
| 110 |
- name: Verify disabled KVM policy creation |
| 111 |
ansible.builtin.assert: |
| 112 |
that: |
| 113 |
- disabled_creation.changed |
| 114 |
- disabled_info.api_response[0].Name == 'test_kvm_policy_disabled' |
| 115 |
- disabled_info.api_response[0].Enabled == false |
| 116 |
|
| 117 |
- name: Create disabled KVM policy (idempotency check) |
| 118 |
cisco.intersight.intersight_kvm_policy: |
| 119 |
<<: *api_info |
| 120 |
name: test_kvm_policy_disabled |
| 121 |
description: "Test disabled KVM policy" |
| 122 |
enabled: false |
| 123 |
tags: |
| 124 |
- Key: Security |
| 125 |
Value: Disabled |
| 126 |
register: disabled_creation_ide |
| 127 |
|
| 128 |
- name: Verify disabled KVM policy creation (idempotency check) |
| 129 |
ansible.builtin.assert: |
| 130 |
that: |
| 131 |
- not disabled_creation_ide.changed |
| 132 |
|
| 133 |
- name: Create KVM policy with custom settings |
| 134 |
cisco.intersight.intersight_kvm_policy: |
| 135 |
<<: *api_info |
| 136 |
name: test_kvm_policy_custom |
| 137 |
description: "Test KVM policy with custom settings" |
| 138 |
enabled: true |
| 139 |
maximum_sessions: 2 |
| 140 |
remote_port: 3000 |
| 141 |
enable_video_encryption: true |
| 142 |
enable_local_server_video: false |
| 143 |
tunneled_kvm_enabled: true |
| 144 |
tags: |
| 145 |
- Key: Environment |
| 146 |
Value: Custom |
| 147 |
register: custom_creation |
| 148 |
|
| 149 |
- name: Fetch info after custom KVM policy creation |
| 150 |
cisco.intersight.intersight_kvm_policy_info: |
| 151 |
<<: *api_info |
| 152 |
name: test_kvm_policy_custom |
| 153 |
register: custom_info |
| 154 |
|
| 155 |
- name: Verify custom KVM policy creation |
| 156 |
ansible.builtin.assert: |
| 157 |
that: |
| 158 |
- custom_creation.changed |
| 159 |
- custom_info.api_response[0].Name == 'test_kvm_policy_custom' |
| 160 |
- custom_info.api_response[0].Enabled == true |
| 161 |
- custom_info.api_response[0].MaximumSessions == 2 |
| 162 |
- custom_info.api_response[0].RemotePort == 3000 |
| 163 |
- custom_info.api_response[0].EnableVideoEncryption == true |
| 164 |
- custom_info.api_response[0].EnableLocalServerVideo == false |
| 165 |
- custom_info.api_response[0].TunneledKvmEnabled == true |
| 166 |
|
| 167 |
- name: Create custom KVM policy (idempotency check) |
| 168 |
cisco.intersight.intersight_kvm_policy: |
| 169 |
<<: *api_info |
| 170 |
name: test_kvm_policy_custom |
| 171 |
description: "Test KVM policy with custom settings" |
| 172 |
enabled: true |
| 173 |
maximum_sessions: 2 |
| 174 |
remote_port: 3000 |
| 175 |
enable_video_encryption: true |
| 176 |
enable_local_server_video: false |
| 177 |
tunneled_kvm_enabled: true |
| 178 |
tags: |
| 179 |
- Key: Environment |
| 180 |
Value: Custom |
| 181 |
register: custom_creation_ide |
| 182 |
|
| 183 |
- name: Verify custom KVM policy creation (idempotency check) |
| 184 |
ansible.builtin.assert: |
| 185 |
that: |
| 186 |
- not custom_creation_ide.changed |
| 187 |
|
| 188 |
- name: Update KVM policy from enabled to disabled |
| 189 |
cisco.intersight.intersight_kvm_policy: |
| 190 |
<<: *api_info |
| 191 |
name: test_kvm_policy_enabled |
| 192 |
description: "Test KVM policy now disabled" |
| 193 |
enabled: false |
| 194 |
tags: |
| 195 |
- Key: Site |
| 196 |
Value: Test |
| 197 |
- Key: Status |
| 198 |
Value: Updated |
| 199 |
register: enabled_to_disabled_update |
| 200 |
|
| 201 |
- name: Verify KVM policy update from enabled to disabled |
| 202 |
ansible.builtin.assert: |
| 203 |
that: |
| 204 |
- enabled_to_disabled_update.changed |
| 205 |
|
| 206 |
- name: Fetch info after disabling KVM policy |
| 207 |
cisco.intersight.intersight_kvm_policy_info: |
| 208 |
<<: *api_info |
| 209 |
name: test_kvm_policy_enabled |
| 210 |
register: disabled_updated_info |
| 211 |
|
| 212 |
- name: Verify KVM policy is now disabled |
| 213 |
ansible.builtin.assert: |
| 214 |
that: |
| 215 |
- disabled_updated_info.api_response[0].Enabled == false |
| 216 |
|
| 217 |
- name: Update KVM policy from disabled to enabled with new settings |
| 218 |
cisco.intersight.intersight_kvm_policy: |
| 219 |
<<: *api_info |
| 220 |
name: test_kvm_policy_disabled |
| 221 |
description: "Test KVM policy now enabled with custom settings" |
| 222 |
enabled: true |
| 223 |
maximum_sessions: 3 |
| 224 |
remote_port: 2500 |
| 225 |
enable_video_encryption: false |
| 226 |
enable_local_server_video: true |
| 227 |
tunneled_kvm_enabled: true |
| 228 |
tags: |
| 229 |
- Key: Security |
| 230 |
Value: Enabled |
| 231 |
register: disabled_to_enabled_update |
| 232 |
|
| 233 |
- name: Verify KVM policy update from disabled to enabled |
| 234 |
ansible.builtin.assert: |
| 235 |
that: |
| 236 |
- disabled_to_enabled_update.changed |
| 237 |
|
| 238 |
- name: Fetch info after enabling KVM policy |
| 239 |
cisco.intersight.intersight_kvm_policy_info: |
| 240 |
<<: *api_info |
| 241 |
name: test_kvm_policy_disabled |
| 242 |
register: enabled_updated_info |
| 243 |
|
| 244 |
- name: Verify KVM policy is now enabled with new settings |
| 245 |
ansible.builtin.assert: |
| 246 |
that: |
| 247 |
- enabled_updated_info.api_response[0].Enabled == true |
| 248 |
- enabled_updated_info.api_response[0].MaximumSessions == 3 |
| 249 |
- enabled_updated_info.api_response[0].RemotePort == 2500 |
| 250 |
|
| 251 |
- name: Test validation failure - maximum_sessions too low |
| 252 |
cisco.intersight.intersight_kvm_policy: |
| 253 |
<<: *api_info |
| 254 |
name: test_kvm_policy_validation |
| 255 |
description: "Test validation failure" |
| 256 |
enabled: true |
| 257 |
maximum_sessions: 0 |
| 258 |
register: validation_max_sessions_low |
| 259 |
failed_when: |
| 260 |
- "'maximum_sessions must be between 1 and 4 (inclusive)' not in validation_max_sessions_low.msg" |
| 261 |
|
| 262 |
- name: Test validation failure - maximum_sessions too high |
| 263 |
cisco.intersight.intersight_kvm_policy: |
| 264 |
<<: *api_info |
| 265 |
name: test_kvm_policy_validation |
| 266 |
description: "Test validation failure" |
| 267 |
enabled: true |
| 268 |
maximum_sessions: 5 |
| 269 |
register: validation_max_sessions_high |
| 270 |
failed_when: |
| 271 |
- "'maximum_sessions must be between 1 and 4 (inclusive)' not in validation_max_sessions_high.msg" |
| 272 |
|
| 273 |
- name: Test validation failure - remote_port too low |
| 274 |
cisco.intersight.intersight_kvm_policy: |
| 275 |
<<: *api_info |
| 276 |
name: test_kvm_policy_validation |
| 277 |
description: "Test validation failure" |
| 278 |
enabled: true |
| 279 |
remote_port: 1000 |
| 280 |
register: validation_remote_port_low |
| 281 |
failed_when: |
| 282 |
- "'remote_port must be between 1024 and 65535 (inclusive)' not in validation_remote_port_low.msg" |
| 283 |
|
| 284 |
- name: Test validation failure - remote_port too high |
| 285 |
cisco.intersight.intersight_kvm_policy: |
| 286 |
<<: *api_info |
| 287 |
name: test_kvm_policy_validation |
| 288 |
description: "Test validation failure" |
| 289 |
enabled: true |
| 290 |
remote_port: 70000 |
| 291 |
register: validation_remote_port_high |
| 292 |
failed_when: |
| 293 |
- "'remote_port must be between 1024 and 65535 (inclusive)' not in validation_remote_port_high.msg" |
| 294 |
|
| 295 |
- name: Fetch all KVM policies under the organization |
| 296 |
cisco.intersight.intersight_kvm_policy_info: |
| 297 |
<<: *api_info |
| 298 |
register: all_policies_info |
| 299 |
|
| 300 |
- name: Check that there are at least 3 KVM policies under this organization |
| 301 |
ansible.builtin.assert: |
| 302 |
that: |
| 303 |
- all_policies_info.api_response | length >= 3 |
| 304 |
|
| 305 |
always: |
| 306 |
- name: Remove test KVM policies |
| 307 |
cisco.intersight.intersight_kvm_policy: |
| 308 |
<<: *api_info |
| 309 |
name: "{{ item }}" |
| 310 |
state: absent |
| 311 |
loop: |
| 312 |
- test_kvm_policy_enabled |
| 313 |
- test_kvm_policy_disabled |
| 314 |
- test_kvm_policy_custom |
| 315 |
- test_kvm_policy_validation |