Interview Prep/Ansible/Vault, Privilege Escalation and Error Handling

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.

All Ansible questions Roadmap: Ansible

More on Vault, Privilege Escalation and Error Handling