# Ansible vault encrypt-decrypt ## Encrypt Echo passwords through ansible-vault into a file (or files). Be sure to escape special characters (see below) or avoid them altogether. ``` " ' [ ] { } > | * & ! % # ` @ , ``` Provide encryption password when prompted (can be different for each password) ```bash printf "%s" | ansible-vault encrypt_string --stdin-name= > .var.yml printf "%s" | ansible-vault encrypt_string --stdin-name= >> .var.yml ``` ## Decrypt Retrieve a single decrytped password from yml file containing vaulted password. Prompt for encryption password. ```bash ansible localhost -e '@.yml' --ask-vault-pass -m debug -a 'var=' ``` Or include reference to vault password if you have it stored in a file ```bash ansible localhost -e '@.yml' --vault-password-file ~/pw.vault -m debug -a 'var=' ```