This commit is contained in:
Matt Reeves 2024-12-31 22:22:40 -05:00
parent a58682c4e7
commit 1335f6c437

View file

@ -17,27 +17,17 @@
- name: Generate .env content - name: Generate .env content
vars: vars:
env_variables: "{{ secret_mapping[target_host]['env_variables'] | default({}) }}" env_variables: "{{ secret_mapping[target_host]['env_variables'] | default({}) }}"
ansible.builtin.shell: | ansible.builtin.template:
#!/bin/bash src: env_template.j2
echo "Generating .env for {{ target_host }} at {{ repo_path }}/.env" dest: "{{ repo_path }}/.env"
for var in "${!env_variables[@]}"; do
secret_id="${env_variables[$var]}" - name: Verify .env file content
if [ -n "$secret_id" ]; then ansible.builtin.shell: cat "{{ repo_path }}/.env"
value=$(bws secret get "$secret_id" | jq -r '.value')
echo "$var=$value"
else
echo "$var="
fi
done
args:
executable: /bin/bash
register: env_file_content register: env_file_content
- name: Write .env file to target host - name: Display .env content
ansible.builtin.copy: ansible.builtin.debug:
dest: "{{ repo_path }}/.env" var: env_file_content.stdout_lines
content: "{{ env_file_content.stdout }}"
mode: '0644'
- name: Ensure the repository is up-to-date - name: Ensure the repository is up-to-date
ansible.builtin.shell: git pull ansible.builtin.shell: git pull