| 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_smtp_policy: |
| 14 |
<<: *api_info |
| 15 |
name: "{{ item }}" |
| 16 |
state: absent |
| 17 |
loop: |
| 18 |
- test_smtp_policy_minimal |
| 19 |
- test_smtp_policy_full |
| 20 |
- test_smtp_policy_disabled |
| 21 |
|
| 22 |
- name: Create SMTP Policy with minimal parameters (check-mode) |
| 23 |
cisco.intersight.intersight_smtp_policy: |
| 24 |
<<: *api_info |
| 25 |
name: test_smtp_policy_minimal |
| 26 |
description: "Test SMTP Policy Minimal" |
| 27 |
state: present |
| 28 |
smtp_server: "smtp.example.com" |
| 29 |
check_mode: true |
| 30 |
register: minimal_creation_check_mode |
| 31 |
|
| 32 |
- name: Verify SMTP Policy was not created (check-mode) |
| 33 |
ansible.builtin.assert: |
| 34 |
that: |
| 35 |
- minimal_creation_check_mode is changed |
| 36 |
- minimal_creation_check_mode.api_response == {} |
| 37 |
|
| 38 |
- name: Create SMTP Policy with minimal parameters |
| 39 |
cisco.intersight.intersight_smtp_policy: |
| 40 |
<<: *api_info |
| 41 |
name: test_smtp_policy_minimal |
| 42 |
description: "Test SMTP Policy Minimal" |
| 43 |
smtp_server: "smtp.example.com" |
| 44 |
state: present |
| 45 |
register: minimal_creation |
| 46 |
|
| 47 |
- name: Fetch info after Minimal SMTP Policy creation |
| 48 |
cisco.intersight.intersight_smtp_policy_info: |
| 49 |
<<: *api_info |
| 50 |
name: test_smtp_policy_minimal |
| 51 |
register: minimal_info |
| 52 |
|
| 53 |
- name: Verify Minimal SMTP Policy creation |
| 54 |
ansible.builtin.assert: |
| 55 |
that: |
| 56 |
- minimal_creation.changed |
| 57 |
- minimal_info.api_response[0].Name == 'test_smtp_policy_minimal' |
| 58 |
- minimal_info.api_response[0].Enabled == true |
| 59 |
- minimal_info.api_response[0].SmtpServer == 'smtp.example.com' |
| 60 |
- minimal_info.api_response[0].SmtpPort == 25 |
| 61 |
- minimal_info.api_response[0].MinSeverity == 'critical' |
| 62 |
|
| 63 |
- name: Create SMTP Policy with minimal parameters (idempotency check) |
| 64 |
cisco.intersight.intersight_smtp_policy: |
| 65 |
<<: *api_info |
| 66 |
name: test_smtp_policy_minimal |
| 67 |
description: "Test SMTP Policy Minimal" |
| 68 |
smtp_server: "smtp.example.com" |
| 69 |
state: present |
| 70 |
register: minimal_creation_ide |
| 71 |
|
| 72 |
- name: Verify Minimal SMTP Policy creation (idempotency check) |
| 73 |
ansible.builtin.assert: |
| 74 |
that: |
| 75 |
- not minimal_creation_ide.changed |
| 76 |
|
| 77 |
- name: Create SMTP Policy with full parameters |
| 78 |
cisco.intersight.intersight_smtp_policy: |
| 79 |
<<: *api_info |
| 80 |
name: test_smtp_policy_full |
| 81 |
description: "Test SMTP Policy Full" |
| 82 |
enabled: true |
| 83 |
smtp_server: "1.2.3.4" |
| 84 |
smtp_port: 2525 |
| 85 |
min_severity: "warning" |
| 86 |
sender_email: "[email protected]" |
| 87 |
smtp_recipients: |
| 88 |
- "[email protected]" |
| 89 |
- "[email protected]" |
| 90 |
tags: |
| 91 |
- Key: Environment |
| 92 |
Value: Test |
| 93 |
state: present |
| 94 |
register: full_creation |
| 95 |
|
| 96 |
- name: Fetch info after Full SMTP Policy creation |
| 97 |
cisco.intersight.intersight_smtp_policy_info: |
| 98 |
<<: *api_info |
| 99 |
name: test_smtp_policy_full |
| 100 |
register: full_info |
| 101 |
|
| 102 |
- name: Verify Full SMTP Policy creation |
| 103 |
ansible.builtin.assert: |
| 104 |
that: |
| 105 |
- full_creation.changed |
| 106 |
- full_info.api_response[0].Name == 'test_smtp_policy_full' |
| 107 |
- full_info.api_response[0].Enabled == true |
| 108 |
- full_info.api_response[0].SmtpServer == '1.2.3.4' |
| 109 |
- full_info.api_response[0].SmtpPort == 2525 |
| 110 |
- full_info.api_response[0].MinSeverity == 'warning' |
| 111 |
- full_info.api_response[0].SenderEmail == '[email protected]' |
| 112 |
- full_info.api_response[0].SmtpRecipients | length == 2 |
| 113 |
|
| 114 |
- name: Update SMTP Policy |
| 115 |
cisco.intersight.intersight_smtp_policy: |
| 116 |
<<: *api_info |
| 117 |
name: test_smtp_policy_full |
| 118 |
description: "Updated Description" |
| 119 |
min_severity: "major" |
| 120 |
smtp_server: "1.2.3.4" |
| 121 |
smtp_recipients: |
| 122 |
- "[email protected]" |
| 123 |
register: policy_update |
| 124 |
|
| 125 |
- name: Fetch info after Update |
| 126 |
cisco.intersight.intersight_smtp_policy_info: |
| 127 |
<<: *api_info |
| 128 |
name: test_smtp_policy_full |
| 129 |
register: update_info |
| 130 |
|
| 131 |
- name: Verify Update |
| 132 |
ansible.builtin.assert: |
| 133 |
that: |
| 134 |
- policy_update.changed |
| 135 |
- update_info.api_response[0].Description == 'Updated Description' |
| 136 |
- update_info.api_response[0].MinSeverity == 'major' |
| 137 |
- update_info.api_response[0].SmtpRecipients | length == 1 |
| 138 |
- update_info.api_response[0].SmtpRecipients[0] == '[email protected]' |
| 139 |
|
| 140 |
- name: Create Disabled SMTP Policy |
| 141 |
cisco.intersight.intersight_smtp_policy: |
| 142 |
<<: *api_info |
| 143 |
name: test_smtp_policy_disabled |
| 144 |
enabled: false |
| 145 |
state: present |
| 146 |
register: disabled_creation |
| 147 |
|
| 148 |
- name: Verify Disabled SMTP Policy |
| 149 |
cisco.intersight.intersight_smtp_policy_info: |
| 150 |
<<: *api_info |
| 151 |
name: test_smtp_policy_disabled |
| 152 |
register: disabled_info |
| 153 |
|
| 154 |
- name: Verify Disabled status |
| 155 |
ansible.builtin.assert: |
| 156 |
that: |
| 157 |
- disabled_creation.changed |
| 158 |
- disabled_info.api_response[0].Enabled == false |
| 159 |
|
| 160 |
always: |
| 161 |
- name: Remove all test SMTP Policies |
| 162 |
cisco.intersight.intersight_smtp_policy: |
| 163 |
<<: *api_info |
| 164 |
name: "{{ item }}" |
| 165 |
state: absent |
| 166 |
loop: |
| 167 |
- test_smtp_policy_minimal |
| 168 |
- test_smtp_policy_full |
| 169 |
- test_smtp_policy_disabled |