Skip to content

Commit 6d188ba

Browse files
committed
refactor
1 parent 75d4819 commit 6d188ba

File tree

5 files changed

+30
-44
lines changed

5 files changed

+30
-44
lines changed

ansible/roles/db/templates/docker-compose.yml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
memory: 512M
3131

3232
pgadmin:
33-
image: dpage/pgadmin4:9.9.0
33+
image: dpage/pgadmin4:9.10.0
3434
container_name: pgadmin
3535
restart: unless-stopped
3636
user: root

ansible/roles/vault/tasks/main.yaml

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
- name: Set variables
66
ansible.builtin.set_fact:
77
remote_path: ~/docker-compose.yml
8-
local_path: docker-compose.yml
8+
template_file: docker-compose.yml
99
project_path: .
1010

1111
- name: Include update docker-compose
1212
ansible.builtin.include_tasks: "{{ tasks_dir }}/docker/update-compose.yaml"
1313
vars:
1414
update_compose_remote_path: "{{ remote_path }}"
15-
update_compose_local_path: "{{ local_path }}"
15+
template_file_name: "{{ template_file }}"
1616
update_compose_project_path: "{{ project_path }}"
1717

1818
- name: Copy init-vault.sh
19-
ansible.builtin.copy:
19+
ansible.builtin.template:
2020
src: init-vault.sh
2121
dest: ~/init-vault.sh
2222
mode: '0755'
@@ -26,15 +26,33 @@
2626
path: ~/config/vault-config.json
2727
register: remote_config
2828

29-
- name: Read local vault-config.json
30-
ansible.builtin.stat:
31-
path: vault-config.json
32-
register: local_config
33-
delegate_to: localhost
29+
- name: Read remote file content
30+
ansible.builtin.slurp:
31+
src: ~/config/vault-config.json
32+
register: remote_config_content
33+
when: remote_config.stat.exists
34+
35+
- name: Render template content
36+
ansible.builtin.set_fact:
37+
template_config_raw: "{{ lookup('template', 'vault-config.json') }}"
38+
39+
- name: Normalize template content to string
40+
ansible.builtin.set_fact:
41+
template_config_rendered: "{{ (template_config_raw | string).strip() }}"
42+
43+
- name: Set default remote content when file doesn't exist
44+
ansible.builtin.set_fact:
45+
remote_content_decoded: ""
46+
when: not remote_config.stat.exists
47+
48+
- name: Decode remote content when file exists
49+
ansible.builtin.set_fact:
50+
remote_content_decoded: "{{ (remote_config_content.content | b64decode | string).strip() }}"
51+
when: remote_config.stat.exists
3452

3553
- name: Check file content and set variables
3654
ansible.builtin.set_fact:
37-
config_different: "{{ not remote_config.stat.exists or remote_config.stat.checksum != local_config.stat.checksum }}"
55+
config_different: "{{ not remote_config.stat.exists or (remote_content_decoded != template_config_rendered) }}"
3856

3957
- name: Are they different?
4058
ansible.builtin.debug:
@@ -50,7 +68,7 @@
5068
mode: '0755'
5169

5270
- name: Copy vault-config.json
53-
ansible.builtin.copy:
71+
ansible.builtin.template:
5472
src: vault-config.json
5573
dest: ~/config/vault-config.json
5674
mode: '0644'
@@ -76,35 +94,3 @@
7694
until: vault_health.status in [200, 429, 473, 501]
7795
retries: 10
7896
delay: 3
79-
80-
- name: Check if Vault is initialized
81-
ansible.builtin.shell: docker exec vault vault status -format=json
82-
register: vault_status
83-
ignore_errors: true
84-
changed_when: false
85-
86-
- name: Display Vault initialization instructions
87-
ansible.builtin.debug:
88-
msg: |
89-
Vault is not initialized. Please run:
90-
91-
docker exec -it vault sh
92-
vault operator init
93-
94-
Save the unseal keys and root token securely!
95-
Then unseal Vault with:
96-
97-
vault operator unseal <key1>
98-
vault operator unseal <key2>
99-
vault operator unseal <key3>
100-
101-
After unsealing, configure OIDC by running init-vault.sh with:
102-
103-
export VAULT_ADDR=http://127.0.0.1:8200
104-
export VAULT_TOKEN=<your-root-token>
105-
export OIDC_DISCOVERY_URL="https://auth.ildoc.it/application/o/vault/"
106-
export OIDC_CLIENT_ID="<client-id-from-authentik>"
107-
export OIDC_CLIENT_SECRET="<client-secret-from-authentik>"
108-
109-
./init-vault.sh
110-
when: vault_status.rc != 0 or (vault_status.stdout | from_json).initialized == false

ansible/roles/vault/files/docker-compose.yml renamed to ansible/roles/vault/templates/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
services:
33
vault:
4-
image: hashicorp/vault:1.21.0@sha256:62dd55c9ccbdc0af0a9269e87481a64650258907434d5ddb5e795e2eb2ac5780
4+
image: hashicorp/vault:1.21.1@sha256:f4e2687b72858a9e2160c344c9fa1ef74c07f21a89a8c00534ab64d3f187b927
55
container_name: vault
66
ports:
77
- "8200:8200"

0 commit comments

Comments
 (0)