Interview Prep/Ansible/Security and Secrets

How do you integrate HashiCorp Vault with Ansible?

AdvancedProductionSecurity and Secrets
Answer

Use the community.hashi_vault collection (it needs the hvac Python library on the controller). Authenticate with AppRole, JWT/OIDC or a cloud auth method rather than a long-lived token.

db_password: >-
  {{ lookup('community.hashi_vault.hashi_vault',
            'secret/data/prod/app:db_password',
            url='https://vault.example.com:8200',
            auth_method='approle',
            role_id=vault_role_id,
            secret_id=vault_secret_id) }}

Issues to design for: the secret_id is itself a secret (deliver it through CI as a short-lived, response-wrapped value), every lookup is a network call so fetch once per play, and Vault policies should give each pipeline access only to its environment's paths. AAP has a native HashiCorp Vault credential type that does this without code.

All Ansible questions Roadmap: Ansible

More on Security and Secrets