| 1 |
--- |
| 2 |
- name: Converge |
| 3 |
hosts: all |
| 4 |
gather_facts: false |
| 5 |
vars: |
| 6 |
https_cert_ssl_failure: {} |
| 7 |
ca_cert_path: "{{ lookup('env', 'ca_cert_path') }}" |
| 8 |
path_for_import_cert: "{{ lookup('env', 'path_for_import_cert') }}" |
| 9 |
|
| 10 |
tasks: |
| 11 |
- name: Fetching firmware version for IDRAC |
| 12 |
ansible.builtin.include_tasks: |
| 13 |
file: ../__extract_firmware_version.yml |
| 14 |
vars: |
| 15 |
idrac_ip: "{{ lookup('env', 'IDRAC_IP') }}" |
| 16 |
idrac_user: "{{ lookup('env', 'IDRAC_USER') }}" |
| 17 |
idrac_password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 18 |
|
| 19 |
- name: Import HTTPS certificate using ssl_key |
| 20 |
block: |
| 21 |
- name: Set fact |
| 22 |
ansible.builtin.set_fact: |
| 23 |
per_mode: "0755" |
| 24 |
|
| 25 |
- name: Create Directory |
| 26 |
ansible.builtin.file: |
| 27 |
path: "{{ path_for_import_cert }}" |
| 28 |
state: directory |
| 29 |
mode: "{{ per_mode }}" |
| 30 |
register: idrac_certificate_created_directory |
| 31 |
check_mode: false |
| 32 |
|
| 33 |
- name: Setting up certificate path |
| 34 |
ansible.builtin.stat: |
| 35 |
path: "{{ path_for_import_cert }}" |
| 36 |
register: idrac_certificate_check_file_created |
| 37 |
check_mode: false |
| 38 |
|
| 39 |
- name: Create SSL Key ans self-signed certificate |
| 40 |
when: idrac_certificate_check_file_created.stat.exists |
| 41 |
ansible.builtin.include_tasks: |
| 42 |
file: ../__get_ssl_key.yml |
| 43 |
|
| 44 |
- name: Importing HTTPS certificate using ssl_key |
| 45 |
ansible.builtin.import_role: |
| 46 |
name: dellemc.openmanage.idrac_certificate |
| 47 |
vars: |
| 48 |
hostname: "{{ lookup('env', 'IDRAC_IP') }}" |
| 49 |
username: "{{ lookup('env', 'IDRAC_USER') }}" |
| 50 |
password: "{{ lookup('env', 'IDRAC_PASSWORD') }}" |
| 51 |
validate_certs: false |
| 52 |
command: "import" |
| 53 |
certificate_type: "HTTPS" |
| 54 |
certificate_path: "{{ path_for_import_cert }}/cert.pem" |
| 55 |
ssl_key: "{{ path_for_import_cert }}/cert.key" |
| 56 |
|
| 57 |
- name: Waiting for idrac readiness |
| 58 |
ansible.builtin.wait_for: |
| 59 |
timeout: 60 |
| 60 |
when: |
| 61 |
- not ansible_check_mode |
| 62 |
- idrac_certificate_out is defined |
| 63 |
- idrac_certificate_out.changed |
| 64 |
|
| 65 |
- name: Asserting operation with check mode. |
| 66 |
ansible.builtin.assert: |
| 67 |
that: idrac_certificate_out.msg == "Changes found to be applied." |
| 68 |
when: ansible_check_mode |
| 69 |
|
| 70 |
- name: Asserting operation with normal mode. |
| 71 |
ansible.builtin.assert: |
| 72 |
that: idrac_certificate_out.msg == "Successfully performed the SSL |
| 73 |
key upload and 'import' certificate operation. |
| 74 |
iDRAC has been reset successfully." |
| 75 |
when: not ansible_check_mode and idrac_certificate_out.changed |
| 76 |
|
| 77 |
- name: Asserting operation with idempotence. |
| 78 |
ansible.builtin.assert: |
| 79 |
that: idrac_certificate_out.msg == "No changes found to be applied." |
| 80 |
when: not ansible_check_mode and not idrac_certificate_out.changed |
| 81 |
|
| 82 |
rescue: |
| 83 |
- name: Set the failure messages for SSLKEY |
| 84 |
ansible.builtin.set_fact: |
| 85 |
https_cert_ssl_failure: "{{ https_cert_ssl_failure | |
| 86 |
combine({'HTTPS_SSL_KEY_CERT_IMPORT': |
| 87 |
{'msg': ansible_failed_result.msg, |
| 88 |
'failed_task_name': ansible_failed_task.name}}) }}" |
| 89 |
|
| 90 |
- name: Collecting failure |
| 91 |
ansible.builtin.debug: |
| 92 |
var: https_cert_ssl_failure |
| 93 |
when: https_cert_ssl_failure is defined |
| 94 |
failed_when: true |
| 95 |
|
| 96 |
always: |
| 97 |
- name: Deleting the directory |
| 98 |
ansible.builtin.include_tasks: |
| 99 |
file: ../__delete_directory.yml |