Interview Prep/Ansible/Testing, CI/CD and Quality

How do you handle secrets in Molecule and CI tests?

BeginnerProductionTesting, CI/CD and Quality
Answer

Tests should never need production secrets. Give each test environment its own dummy values:

  • In Molecule, set test values in provisioner.inventory.group_vars inside molecule.yml, or in a test-only vars file committed in plain text because the values are fake.
  • If the role reads vault-encrypted vars, keep a separate test vault file encrypted with a test-only vault ID whose password lives in a CI secret.
  • Point lookups (Vault, Secrets Manager) at a dev instance or mock them with a variable override.
provisioner:
  name: ansible
  inventory:
    group_vars:
      all:
        db_password: "molecule-not-a-secret"

If a test job ever needs the prod vault password, the test is designed wrong.

All Ansible questions Roadmap: Ansible

More on Testing, CI/CD and Quality