Skip to content

Commit

Permalink
add existing file encryption check
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxBed4d committed Nov 19, 2024
1 parent 53027c6 commit ecac530
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion etc/kayobe/ansible/wazuh-secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
path: "{{ wazuh_secrets_path }}"
register: waz_exist_result

- name: Check if secret is encrypted
block:
- name: Try to decrypt secret
no_log: True
copy:
content: "{{ lookup('ansible.builtin.file', wazuh_secrets_path) | ansible.builtin.vault(ansible_vault_password) }}"
dest: "{{ wazuh_secrets_path }}"
decrypt: True
vars:
ansible_vault_password: "{{ lookup('ansible.builtin.env', 'KAYOBE_VAULT_PASSWORD') }}"
rescue:
- name: Secrets already decrypted
ansible.builtin.debug:
msg: 'Secret was already decrypted'
when: waz_exist_result.stat.exists

- name: Template new secrets
no_log: True
template:
Expand All @@ -34,4 +50,3 @@
decrypt: false
vars:
ansible_vault_password: "{{ lookup('ansible.builtin.env', 'KAYOBE_VAULT_PASSWORD') }}"
when: not waz_exist_result.stat.exists

0 comments on commit ecac530

Please sign in to comment.