Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make vault init more idempotent #14664

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions tools/docker-compose/ansible/roles/vault/tasks/initialize.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
---
- name: See if vault has been initialized
ansible.builtin.stat:
path: "{{ vault_file }}"
register: vault_secret_file_info

- block:
- name: Start the vault
community.docker.docker_compose:
state: present
services: vault
project_src: "{{ sources_dest }}"
register: vault_start

- name: Run the initialization
community.docker.docker_container_exec:
Expand All @@ -18,6 +14,7 @@
env:
VAULT_ADDR: "http://127.0.0.1:1234"
register: vault_initialization
ignore_errors: true

- name: Write out initialization file
copy:
Expand All @@ -30,6 +27,7 @@
{{ vault_initialization.stdout_lines[4] | regex_replace('Unseal Key ', 'Unseal_Key_') }}
{{ vault_initialization.stdout_lines[6] | regex_replace('Initial Root Token', 'Initial_Root_Token') }}
dest: "{{ vault_file }}"
when: (vault_initialization.stdout_lines | length) > 0

- name: Unlock the vault
include_role:
Expand Down Expand Up @@ -58,5 +56,4 @@
community.docker.docker_compose:
state: absent
project_src: "{{ sources_dest }}"

when: not vault_secret_file_info.stat.exists
when: vault_start is defined and vault_start.changed
Loading