Interview Prep/Ansible/Vault, Performance and Execution Behaviour

`Vault format unhexlify error: Odd-length string` after pasting an `encrypt_string` value

IntermediateTroubleshootingVault, Performance and Execution Behaviour
Answer

Likely causes → The !vault | block was damaged when pasted: lines re-wrapped, a line dropped, inconsistent indentation, or the trailing digits cut off. Non-hexadecimal digit found points to the same problem.

Fix → Generate the value again and paste it as one block:

ansible-vault encrypt_string --vault-id prod@prompt --stdin-name db_password
db_password: !vault |
  $ANSIBLE_VAULT;1.2;AES256;prod
  6233...   # every line indented the same, no edits

Check with ansible localhost -m debug -a var=db_password -e @file.yml --vault-id prod@prompt.

Prevent → For many secrets, prefer whole-file encryption (vault.yml), which cannot be mangled by YAML indentation.

All Ansible questions Roadmap: Ansible

More on Vault, Performance and Execution Behaviour