Part XXI covers what Ansible Vault is, how to encrypt with it, how to
rekey, and what the vault id labels do and do not enforce. This lesson
assumes all of that and asks one structural question:
Can a developer with development credentials decrypt production secrets,
even by accident?
The answer you want is no, and getting there is less about ansible-vault
options than about which password file is on which machine.
The layout
Encrypted material lives inside the environment directory, beside the
plaintext variables it belongs with:
Three properties matter here and none of them is about encryption.
One vault id per environment, with a distinct password. Not one
password with three labels. The label does not restrict anything; the
password does.
A separate vault.yml rather than encrypting main.yml in place. An
encrypted whole file cannot be diffed or reviewed, so putting the
non-secret variables in it makes every ordinary change invisible to
review. Split them and the plaintext file stays reviewable.
Encrypted files sit in the environment tree, not in a shared
group_vars/ beside the playbook. A shared one applies to every
environment — which means every environment needs the password to read
it, which means there is no separation.
What the label actually does
This is the part people get wrong, and the consequence is a scheme that
looks separated and is not.
A vault id label is recorded in the file header:
Read-only / Safethe header carries the label— Real output from ansible-core 2.21.3. The 1.2 format records the vault id as the fourth field.
$ head -1 inventories/production/group_vars/all/vault.yml
$ANSIBLE_VAULT;1.2;AES256;prod
That label tells Ansible which supplied password to try first. By
default it does not restrict which passwords may be tried at all. Offer
the production password under the label dev and the file opens anyway:
Read-only / Safethe label does not have to be true— Real output from ansible-core 2.21.3. The label says dev; the file behind it is the production password. The prod-labelled file decrypts.
Part XXI’s vault-id lesson covers DEFAULT_VAULT_ID_MATCH, the setting
that makes the label binding, and it is worth turning on. But do not mistake
it for the control. The reason a developer cannot read production secrets
is not that a label mismatched — it is that the production password was
never on their machine.
What a wrong vault id does to a run
This is the good news, and it is worth knowing precisely, because it means
the mistake fails in the safest possible way.
Group variables are decrypted while the play is being set up, before any
host is contacted. A wrong password therefore stops the run before a
single connection is attempted:
Configuration changeproduction inventory, development vault id— Real output from ansible-core 2.21.3. The play stops at variable load. No task ran, no host was contacted, and there is no PLAY RECAP because no play completed.
PLAY [Configure web tier] ******************************************************
[ERROR]: Decryption failed (no vault secrets were found that could decrypt).
Exit status 4. Zero tasks attempted, zero hosts touched, no recap.
That is the behaviour you want from a wrong-credential mistake, and it is
worth stating in the runbook: if you see this error against production,
you supplied the wrong vault id — nothing has been changed.
The same property applies to inventory inspection, which is easy to
forget when you are only trying to look at something:
Read-only / Safeyou cannot even list the inventory without the password— Real output from ansible-core 2.21.3. group_vars loading is not optional, so an encrypted file in the tree makes the password mandatory for inspection too.
[ERROR]: Attempting to decrypt but no vault secrets found.
Knowledge check
Knowledge check · 4 questions
Q1. What actually prevents a developer with the dev vault password from decrypting production secrets?
Q2. A run against the production inventory is given only the development vault id. Which statements are true of what happens next, on 2.21.3? Select all that apply.
Q3. Adding ansible-playbook --syntax-check against the production inventory to CI will catch a misconfigured vault id before deploy time.
Q4. Which of these is the most dangerous entry in a vault password distribution table?
Passing score: 75%. Answers are checked in this browser.