Ansible interview question · Most asked

How do you manage secrets with Ansible Vault?

How you'd do it Asked in DevOps Engineer interviews

Members can save this page, take notes and track progress. See membership · Sign in

Summary

Ansible Vault encrypts files or single variables with AES-256 so secrets can live in the repository encrypted. Keep secrets in dedicated vault files (group_vars/prod/vault.yml), reference them from plain variables, and supply the vault password at run time from a password file, a script or the CI system's secret store, never from the repository.

Longer Answer

Common practice:

  • Split plain and secret variables: group_vars/prod/vars.yml holds db_password: "{{ vault_db_password }}" and vault.yml (encrypted) holds vault_db_password. You can still grep for where a secret is used.
  • One vault ID per environment (--vault-id dev@prompt --vault-id prod@/run/secrets/prod-vault), so developers can decrypt dev but not prod.
  • no_log: true on tasks that handle secrets, so values never reach logs or CI output.
  • Rotate: ansible-vault rekey changes the vault password; rotating the secret itself means editing the value and re-running.
  • For larger setups, read secrets at run time from HashiCorp Vault, AWS Secrets Manager or Azure Key Vault with a lookup plugin instead of storing them in the repo at all.

Example

ansible-vault create inventories/prod/group_vars/all/vault.yml
ansible-vault encrypt_string 's3cr3t' --name 'vault_api_key'
ansible-playbook site.yml -i inventories/prod --vault-id prod@/run/secrets/prod-vault-pass

Key Points

  • Encrypt files or single values; keep them in vault-only files.
  • Vault password comes from outside the repo.
  • Separate vault IDs per environment.
  • Use no_log on secret-handling tasks.
  • Consider an external secret manager with lookups.

Explanation

What interviewers look for

Layout (vault files referenced by plain variables), how the password is supplied in CI, no_log, and awareness of external secret managers.

More Ansible questions

← All Ansible questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake