Add secret loading from tofu state and infisical
This commit is contained in:
parent
a46646ae5f
commit
b88054c97e
3 changed files with 48 additions and 0 deletions
4
bin/tofu
Executable file
4
bin/tofu
Executable file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# Used as a workaround for the cloud.terraform collection
|
||||||
|
|
||||||
|
tofu "$@"
|
||||||
|
|
@ -4,6 +4,10 @@
|
||||||
vars:
|
vars:
|
||||||
host_services: "{{ all_services | services_for_host(inventory_hostname) }}"
|
host_services: "{{ all_services | services_for_host(inventory_hostname) }}"
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Load secrets
|
||||||
|
ansible.builtin.import_tasks: tasks/load-secrets.yml
|
||||||
|
tags: always
|
||||||
|
|
||||||
- name: Install software
|
- name: Install software
|
||||||
ansible.builtin.include_role:
|
ansible.builtin.include_role:
|
||||||
name: software
|
name: software
|
||||||
|
|
|
||||||
40
playbooks/tasks/load-secrets.yml
Normal file
40
playbooks/tasks/load-secrets.yml
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
- name: Login to Infisical
|
||||||
|
infisical.vault.login:
|
||||||
|
url: "https://app.infisical.com"
|
||||||
|
auth_method: universal_auth
|
||||||
|
universal_auth_client_id: "{{ lookup('env', 'INFISICAL_UNIVERSAL_AUTH_CLIENT_ID') }}"
|
||||||
|
universal_auth_client_secret: "{{ lookup('env', 'INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET') }}"
|
||||||
|
register: infisical_login
|
||||||
|
delegate_to: localhost
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Read all secrets as dictionary
|
||||||
|
infisical.vault.read_secrets:
|
||||||
|
login_data: "{{ infisical_login.login_data }}"
|
||||||
|
project_id: "{{ lookup('env', 'TF_VAR_infisical_workspace_id') }}"
|
||||||
|
env_slug: "prod"
|
||||||
|
path: "/ansible"
|
||||||
|
as_dict: false
|
||||||
|
register: secrets
|
||||||
|
delegate_to: localhost
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
|
- name: Export secrets as vars
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
"{{ item.key }}": "{{ item.value }}"
|
||||||
|
loop: "{{ secrets.secrets }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.key }}"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Load the opentofu output
|
||||||
|
set_fact:
|
||||||
|
opentofu: "{{ opentofu | default({}) | combine({ item.key: item.value.value }) }}"
|
||||||
|
loop: "{{ lookup('cloud.terraform.tf_output', binary_path='bin/tofu') | dict2items }}"
|
||||||
|
loop_control:
|
||||||
|
label: "{{ item.key }}"
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Set variables from opentofu output
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
all_services: "{{ opentofu.services }}"
|
||||||
Loading…
Reference in a new issue