The blog about containerisation, virtual machines and useful shell snippets and findings

ansible vault quick encryption

it was convenient for me to use zsh function for the string encryption:

add this to .zshrc

vault() {
	echo -n $1 | ansible-vault encrypt_string --vault-id=myvault
}

and use like this

vault my-password

output should be similar to this

Reading plaintext input from stdin. (ctrl-d to end input)
!vault |
          $ANSIBLE_VAULT;1.1;AES256
          39383538336133613537376463373062363639343761633365666530313363343766663662336530
          6637336536383438333038623865386636383737393165340a663236336463306261386466326262
          31333664393130313734303230356364626335346336363430303036633962343536353137376665
          3464363163346433350a653230336636643562363030383363336166636365313133343563393261
          38396530616261616338626161363133323430323361623164393466333038326637
Encryption successful