Skip to content

Commit 8fc30a7

Browse files
committed
add checksum to prevent re-encryption
1 parent 0d10560 commit 8fc30a7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

etc/kayobe/ansible/wazuh-secrets.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,45 @@
1414
path: "{{ wazuh_secrets_path | dirname }}"
1515
state: directory
1616

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+
1747
- name: Template new secrets
1848
no_log: True
1949
template:
2050
src: wazuh-secrets.yml.j2
2151
dest: "{{ wazuh_secrets_path }}"
52+
when: not waz_exist_result.stat.exists
2253

2354
- name: In-place encrypt wazuh-secrets
55+
no_log: True
2456
copy:
2557
content: "{{ lookup('ansible.builtin.file', wazuh_secrets_path) | ansible.builtin.vault(ansible_vault_password) }}"
2658
dest: "{{ wazuh_secrets_path }}"

0 commit comments

Comments
 (0)