Interview Prep/Ansible/Security: Vault, Become and Compliance

Database passwords are sitting in plain text in `group_vars`. How do you fix it?

BeginnerScenarioSecurity: Vault, Become and Compliance
Answer

Situation read → Secrets in Git.

What I'd do →

  1. Encrypt the file: ansible-vault encrypt group_vars/prod/vault.yml.
  2. Keep a plain vars.yml that references vault_ variables.
  3. Pass the password via --vault-password-file or --vault-id.
  4. Rotate any password that was ever committed in plain text.
# group_vars/prod/vars.yml
db_password: "{{ vault_db_password }}"

Why → The prefix pattern keeps names greppable while values stay encrypted.

Interview tip → Rotating is non-negotiable; Git history still holds the old value.

All Ansible questions Roadmap: Ansible

More on Security: Vault, Become and Compliance