Interview Prep/Ansible/Security and Secrets

How do you keep secrets out of Git?

BeginnerProductionSecurity and Secrets
Answer
  • Encrypt anything sensitive with Vault before committing, and name files so it is obvious (vault.yml).
  • A pre-commit hook that rejects unencrypted vault files (check the $ANSIBLE_VAULT; header) plus a scanner such as gitleaks or detect-secrets in pre-commit and CI.
  • .gitignore for *.pem, .vault_pass, *.retry, collections/.
  • Branch protection so the CI scan cannot be skipped.

If a secret does get committed, treat it as compromised: rotate it first, then clean history. Rewriting history alone does not un-leak anything.

All Ansible questions Roadmap: Ansible

More on Security and Secrets