Add secret loading from tofu state and infisical

This commit is contained in:
Tobias Reisinger 2026-11-01 14:20:34 +01:00
commit b88054c97e
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
3 changed files with 48 additions and 0 deletions

4
bin/tofu Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env sh
# Used as a workaround for the cloud.terraform collection
tofu "$@"

View file

@ -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

View 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 }}"