What is `encrypt_string` and when is it better than encrypting a whole file?
IntermediateConceptVault, Privilege Escalation and Error Handling
Answer
It encrypts a single value that you paste inline into a normal vars file, leaving the other keys readable.
ansible-vault encrypt_string --vault-id prod@prompt 'S3cret!' --name 'db_password'
db_password: !vault |
$ANSIBLE_VAULT;1.2;AES256;prod
6338343936...
Inline strings keep variable names visible, which helps grep and code review. The downsides: diffs on the encrypted block are opaque, and the data is easy to leak if copy-pasted into the wrong place. Whole-file encryption of a vault.yml is simpler to rotate.
More on Vault, Privilege Escalation and Error Handling
What is Ansible Vault?BeginnerWhich `ansible-vault` commands do you use day to day?BeginnerHow do you supply the vault password when running a playbook?BeginnerWhat are vault IDs and why use them?AdvancedHow is Vault data encrypted and what does the file look like?AdvancedHow do you rotate a vault password?Intermediate