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_varsinsidemolecule.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.
More on Testing, CI/CD and Quality
What does a testing pyramid look like for Ansible code?BeginnerHow do you roll out `ansible-lint` profiles across a team without blocking everyone?IntermediateWhen do you use `skip_list`, `warn_list` and `# noqa`?IntermediateHow do you set up pre-commit hooks for an Ansible repo?BeginnerHow is a Molecule scenario laid out, and what does `molecule test` actually run?IntermediateDocker, Podman or real VMs as the Molecule driver: how do you choose?Advanced