|
14 | 14 | path: "{{ wazuh_secrets_path | dirname }}"
|
15 | 15 | state: directory
|
16 | 16 |
|
| 17 | + - name: Check whether wazuh-secrets.yml exists |
| 18 | + stat: |
| 19 | + path: "{{ wazuh_secrets_path }}" |
| 20 | + register: waz_exist_result |
| 21 | + |
| 22 | + - name: Decrypt wazuh-secrets to checksum |
| 23 | + no_log: True |
| 24 | + copy: |
| 25 | + content: "{{ lookup('ansible.builtin.file', wazuh_secrets_path) | ansible.builtin.vault(ansible_vault_password) }}" |
| 26 | + dest: "{{ wazuh_secrets_path }}" |
| 27 | + decrypt: true |
| 28 | + vars: |
| 29 | + ansible_vault_password: "{{ lookup('ansible.builtin.env', 'KAYOBE_VAULT_PASSWORD') }}" |
| 30 | + when: waz_exist_result.stat.exists |
| 31 | + |
| 32 | + - name: Template new secrets |
| 33 | + no_log: True |
| 34 | + template: |
| 35 | + src: wazuh-secrets.yml.j2 |
| 36 | + dest: "/tmp/wazuh-secrets.yml" |
| 37 | + when: waz_exist_result.stat.exists |
| 38 | + |
| 39 | + - name: Copy for checksum |
| 40 | + no_log: True |
| 41 | + copy: |
| 42 | + content: "{{ lookup('ansible.builtin.file', '/tmp/wazuh-secrets.yml') }}" |
| 43 | + dest: "{{ wazuh_secrets_path }}" |
| 44 | + checksum: yes |
| 45 | + when: waz_exist_result.stat.exists |
| 46 | + |
17 | 47 | - name: Template new secrets
|
18 | 48 | no_log: True
|
19 | 49 | template:
|
20 | 50 | src: wazuh-secrets.yml.j2
|
21 | 51 | dest: "{{ wazuh_secrets_path }}"
|
| 52 | + when: not waz_exist_result.stat.exists |
22 | 53 |
|
23 | 54 | - name: In-place encrypt wazuh-secrets
|
| 55 | + no_log: True |
24 | 56 | copy:
|
25 | 57 | content: "{{ lookup('ansible.builtin.file', wazuh_secrets_path) | ansible.builtin.vault(ansible_vault_password) }}"
|
26 | 58 | dest: "{{ wazuh_secrets_path }}"
|
|
0 commit comments