| 1 |
--- |
| 2 |
- name: Converge |
| 3 |
hosts: all |
| 4 |
gather_facts: false |
| 5 |
vars: |
| 6 |
ca_cert_path: "{{ lookup('env', 'ca_cert_path') }}" |
| 7 |
cert_export_path: "{{ lookup('env', 'certificate_path') }}" |
| 8 |
import_cert_path: "{{ lookup('env', 'path_for_import_cert') }}" |
| 9 |
custom_cert_name: "{{ lookup('env', 'custom_cert_name') }}" |
| 10 |
cust_crt_name_pass: "{{ lookup('env', 'custom_cert_name_pass') }}" |
| 11 |
csc_pass_cert: "{{ lookup('env', 'csc_passphrase_certificate') }}" |
| 12 |
|
| 13 |
tasks: |
| 14 |
- name: Invalid Scenarios |
| 15 |
when: not ansible_check_mode |
| 16 |
block: |
| 17 |
- name: Set the failure messages |
| 18 |
ansible.builtin.set_fact: |
| 19 |
ssl_key_fail_msg: "Unable to locate the SSL key file" |
| 20 |
ctc_invalid_path: "[Errno 2] No such file or directory" |
| 21 |
|
| 22 |
- name: Create directory and fetch certificates |
| 23 |
ansible.builtin.include_tasks: |
| 24 |
file: ../__get_helper.yml |
| 25 |
vars: |
| 26 |
idrac_cert_name: |
| 27 |
- "{{ custom_cert_name }}" |
| 28 |
- "{{ cust_crt_name_pass }}" |
| 29 |
- "{{ csc_pass_cert }}" |
| 30 |
|
| 31 |
- name: Negative - invalid idrac user |
| 32 |
ansible.builtin.import_role: |
| 33 |
name: dellemc.openmanage.idrac_certificate |
| 34 |
vars: |
| 35 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 36 |
username: invalid |
| 37 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 38 |
validate_certs: false |
| 39 |
command: "reset" |
| 40 |
certificate_type: "HTTPS" |
| 41 |
register: invalid_idrac_user |
| 42 |
ignore_errors: true |
| 43 |
|
| 44 |
- name: Verify task status - Negative - invalid idrac user |
| 45 |
ansible.builtin.assert: |
| 46 |
that: |
| 47 |
- idrac_certificate_out.failed |
| 48 |
- '"HTTP Error 401: Unauthorized" in |
| 49 |
idrac_certificate_out.msg' |
| 50 |
|
| 51 |
- name: Negative - invalid idrac password |
| 52 |
ansible.builtin.import_role: |
| 53 |
name: dellemc.openmanage.idrac_certificate |
| 54 |
vars: |
| 55 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 56 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 57 |
password: invalid |
| 58 |
validate_certs: false |
| 59 |
command: "reset" |
| 60 |
certificate_type: "HTTPS" |
| 61 |
register: invalid_idrac_pass |
| 62 |
ignore_errors: true |
| 63 |
ignore_unreachable: true |
| 64 |
|
| 65 |
- name: Verify task status - Negative - invalid idrac password |
| 66 |
ansible.builtin.assert: |
| 67 |
that: |
| 68 |
- idrac_certificate_out.failed |
| 69 |
- '"HTTP Error 401: Unauthorized" in idrac_certificate_out.msg' |
| 70 |
|
| 71 |
- name: Create SSL Key ans self-signed certificate |
| 72 |
when: idrac_certificate_check_file_created is defined and |
| 73 |
idrac_certificate_check_file_created.stat.exists |
| 74 |
ansible.builtin.include_tasks: |
| 75 |
file: ../__get_ssl_key.yml |
| 76 |
|
| 77 |
- name: Import CTC invalid certificate |
| 78 |
ansible.builtin.import_role: |
| 79 |
name: dellemc.openmanage.idrac_certificate |
| 80 |
vars: |
| 81 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 82 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 83 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 84 |
validate_certs: false |
| 85 |
command: "import" |
| 86 |
certificate_type: "CLIENT_TRUST_CERTIFICATE" |
| 87 |
certificate_path: "{{ import_cert_path }}{{ custom_cert_name }}" |
| 88 |
register: idrac_certificate_out |
| 89 |
ignore_errors: true |
| 90 |
ignore_unreachable: true |
| 91 |
|
| 92 |
- name: Waiting for idrac readiness |
| 93 |
ansible.builtin.wait_for: |
| 94 |
timeout: 30 |
| 95 |
when: |
| 96 |
- not ansible_check_mode |
| 97 |
|
| 98 |
- name: Verifying Import a Client Trust Certificate invalid certificate |
| 99 |
ansible.builtin.assert: |
| 100 |
that: |
| 101 |
- '"HTTP Error 400" in idrac_certificate_out.msg' |
| 102 |
- idrac_certificate_out.failed |
| 103 |
|
| 104 |
- name: Import a Client Trust Certificate invalid path |
| 105 |
ansible.builtin.import_role: |
| 106 |
name: dellemc.openmanage.idrac_certificate |
| 107 |
vars: |
| 108 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 109 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 110 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 111 |
validate_certs: false |
| 112 |
command: "import" |
| 113 |
certificate_type: "CLIENT_TRUST_CERTIFICATE" |
| 114 |
certificate_path: "/tmp/certificate.pem" |
| 115 |
ignore_errors: true |
| 116 |
register: idrac_certificate_out |
| 117 |
|
| 118 |
- name: Verifying Import a Client Trust Certificate invalid path |
| 119 |
ansible.builtin.assert: |
| 120 |
that: |
| 121 |
- idrac_certificate_out.failed |
| 122 |
- "ctc_invalid_path in idrac_certificate_out.msg" |
| 123 |
|
| 124 |
- name: Negative - unreachable host |
| 125 |
ansible.builtin.import_role: |
| 126 |
name: dellemc.openmanage.idrac_certificate |
| 127 |
vars: |
| 128 |
hostname: "999.999.999.999" |
| 129 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 130 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 131 |
validate_certs: false |
| 132 |
command: "reset" |
| 133 |
certificate_type: "HTTPS" |
| 134 |
register: invalid_unreachable |
| 135 |
ignore_errors: true |
| 136 |
ignore_unreachable: true |
| 137 |
|
| 138 |
- name: Verify task status - Negative - invalid unreachable host |
| 139 |
ansible.builtin.assert: |
| 140 |
that: >- |
| 141 |
'"<urlopen error [Errno -2] Name or service not known>" in |
| 142 |
idrac_certificate_out.msg' and idrac_certificate_out.unreachable |
| 143 |
|
| 144 |
- name: Invalid command |
| 145 |
ansible.builtin.import_role: |
| 146 |
name: dellemc.openmanage.idrac_certificate |
| 147 |
vars: |
| 148 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 149 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 150 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 151 |
validate_certs: false |
| 152 |
command: "invalid" |
| 153 |
certificate_type: "HTTPS" |
| 154 |
register: invalid_command |
| 155 |
ignore_errors: true |
| 156 |
|
| 157 |
- name: Verify task status - Negative - invalid command |
| 158 |
ansible.builtin.assert: |
| 159 |
that: |
| 160 |
- not idrac_certificate_out.changed |
| 161 |
|
| 162 |
- name: Invalid passphrase |
| 163 |
ansible.builtin.import_role: |
| 164 |
name: dellemc.openmanage.idrac_certificate |
| 165 |
vars: |
| 166 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 167 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 168 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 169 |
validate_certs: false |
| 170 |
command: "import" |
| 171 |
certificate_type: "CSC" |
| 172 |
certificate_path: "{{ import_cert_path }}{{ csc_pass_cert }}" |
| 173 |
passphrase: "invalid" |
| 174 |
register: invalid_passphrase |
| 175 |
ignore_errors: true |
| 176 |
|
| 177 |
- name: Verify task status - Negative - invalid passphrase |
| 178 |
ansible.builtin.assert: |
| 179 |
that: |
| 180 |
- idrac_certificate_out.failed |
| 181 |
- not idrac_certificate_out.changed |
| 182 |
- '"HTTP Error 400: Bad Request" in idrac_certificate_out.msg' |
| 183 |
|
| 184 |
- name: Invalid certificate parameters to generate signing request |
| 185 |
ansible.builtin.import_role: |
| 186 |
name: dellemc.openmanage.idrac_certificate |
| 187 |
vars: |
| 188 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 189 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 190 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 191 |
validate_certs: false |
| 192 |
command: "generate_csr" |
| 193 |
certificate_type: "HTTPS" |
| 194 |
certificate_path: "/root/" |
| 195 |
cert_params: |
| 196 |
invalid_args: "invalid" |
| 197 |
register: invalid_cert_params |
| 198 |
ignore_errors: true |
| 199 |
|
| 200 |
- name: Verify task status - Negative - |
| 201 |
Invalid certificate parameters to generate signing request |
| 202 |
ansible.builtin.assert: |
| 203 |
that: |
| 204 |
- idrac_certificate_out.failed |
| 205 |
- not idrac_certificate_out.changed |
| 206 |
- "'missing required arguments: common_name, country_code, |
| 207 |
locality_name, organization_name, organization_unit, |
| 208 |
state_name found in cert_params' == idrac_certificate_out.msg" |
| 209 |
|
| 210 |
- name: Invalid passphrase for a valid custom |
| 211 |
certificate without passphrase |
| 212 |
ansible.builtin.import_role: |
| 213 |
name: dellemc.openmanage.idrac_certificate |
| 214 |
vars: |
| 215 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 216 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 217 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 218 |
validate_certs: false |
| 219 |
command: "import" |
| 220 |
certificate_type: "CUSTOMCERTIFICATE" |
| 221 |
certificate_path: "{{ import_cert_path }}{{ custom_cert_name }}" |
| 222 |
passphrase: "invalid" |
| 223 |
register: invalid_custom_cert_pass |
| 224 |
ignore_errors: true |
| 225 |
|
| 226 |
- name: Verify task status |
| 227 |
- Negative - invalid custom certificate passphrase |
| 228 |
ansible.builtin.assert: |
| 229 |
that: |
| 230 |
- idrac_certificate_out.failed |
| 231 |
- not idrac_certificate_out.changed |
| 232 |
- '"HTTP Error 400: Bad Request" in idrac_certificate_out.msg' |
| 233 |
|
| 234 |
- name: Invalid custom certificate |
| 235 |
passphrase for a valid custom certificate |
| 236 |
ansible.builtin.import_role: |
| 237 |
name: dellemc.openmanage.idrac_certificate |
| 238 |
vars: |
| 239 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 240 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 241 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 242 |
validate_certs: false |
| 243 |
command: "import" |
| 244 |
certificate_type: "CUSTOMCERTIFICATE" |
| 245 |
certificate_path: "{{ import_cert_path }}/{{ cust_crt_name_pass }}" |
| 246 |
passphrase: "invalid" |
| 247 |
register: invalid_custom_cert_without_pass |
| 248 |
ignore_errors: true |
| 249 |
|
| 250 |
- name: Verify task status - Negative - invalid custom certificate |
| 251 |
passphrase for a valid custom certificate |
| 252 |
ansible.builtin.assert: |
| 253 |
that: |
| 254 |
- idrac_certificate_out.failed |
| 255 |
- not idrac_certificate_out.changed |
| 256 |
- '"HTTP Error 400: Bad Request" in idrac_certificate_out.msg' |
| 257 |
|
| 258 |
- name: Invalid ssl key |
| 259 |
ansible.builtin.import_role: |
| 260 |
name: dellemc.openmanage.idrac_certificate |
| 261 |
vars: |
| 262 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 263 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 264 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 265 |
validate_certs: false |
| 266 |
command: "import" |
| 267 |
certificate_type: "HTTPS" |
| 268 |
certificate_path: "{{ import_cert_path }}cert.pem" |
| 269 |
ssl_key: "invalid" |
| 270 |
register: invalid_ssl_key |
| 271 |
ignore_errors: true |
| 272 |
|
| 273 |
- name: Verify task status - Negative - invalid ssl key |
| 274 |
ansible.builtin.assert: |
| 275 |
that: |
| 276 |
- idrac_certificate_out.failed |
| 277 |
- not idrac_certificate_out.changed |
| 278 |
- '"Unable to locate the SSL key file at |
| 279 |
invalid." in idrac_certificate_out.msg' |
| 280 |
|
| 281 |
- name: Invalid certificate path |
| 282 |
ansible.builtin.import_role: |
| 283 |
name: dellemc.openmanage.idrac_certificate |
| 284 |
vars: |
| 285 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 286 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 287 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 288 |
validate_certs: false |
| 289 |
command: "export" |
| 290 |
certificate_type: "HTTPS" |
| 291 |
certificate_path: "invalid_dir" |
| 292 |
register: invalid_cert_path |
| 293 |
ignore_errors: true |
| 294 |
|
| 295 |
- name: Verify task status - Negative - invalid certificate path |
| 296 |
ansible.builtin.assert: |
| 297 |
that: |
| 298 |
- idrac_certificate_out.failed |
| 299 |
- not idrac_certificate_out.changed |
| 300 |
- '"is not valid." in idrac_certificate_out.msg' |
| 301 |
- idrac_certificate_out.msg == "Provided directory |
| 302 |
path 'invalid_dir' is not valid." |
| 303 |
|
| 304 |
always: |
| 305 |
- name: Deleting the directory |
| 306 |
ansible.builtin.include_tasks: |
| 307 |
file: ../__delete_directory.yml |