Ansible - Ansible-vault

1 - About

ansible-vault is a command line utility that permits to add/get sensitive data (file or property value) into an encrypted format called a vault

Example of sensitive data:

When running a playbook, Ansible finds:

  • the sensitive variables from an encrypted file / string
  • and the other variables in a unencrypted file / string

Encrypted data can include

  • group_vars/ or host_vars inventory variables,
  • variables loaded by *include_vars* or *vars_files*, or variable files
  • variables passed at the command line via the *-e @file.yml* or *-e @file.json* option of ansible-playbook
  • Role variables and defaults are also included
  • Ansible tasks, handlers, and other objects because they are data
  • An individual task file

The vault id used with vault currently must be the same for all files you wish to use together at the same time.

3 - Syntax

Usage: ansible-vault [create|decrypt|edit|encrypt|encrypt_string|rekey|view] [options] [vaultfile.yml]

encryption/decryption utility for Ansible data files

  --ask-vault-pass      ask for vault password
  -h, --help            show this help message and exit
                        the new vault identity to use for rekey
                        new vault password file for rekey
  --vault-id=VAULT_IDS  the vault identity to use
                        vault password file
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)
  --version             show program's version number and exit

 See 'ansible-vault <command> --help' for more information on a specific

4 - Management

4.1 - Encrypt

When encrypting content one vault-id can be used.

4.1.1 - String

4.1.2 - File

ansible-vault encrypt

4.2 - Decrypt

4.2.1 - Decrypt-string

4.3 - Run

4.3.1 - Password file

  • to use a password file dev-password for the label dev:

ansible-playbook --vault-id [email protected] site.yml

ansible-playbook --vault-password-file dev-password site.yml


  • to use a password store in the text file /path/to/my/vault-password-file:

ansible-playbook --vault-id /path/to/my/vault-password-file site.yml

4.3.2 - Prompt

  • To prompt for the dev vault id

ansible-playbook --vault-id [email protected] site.yml
# Prior to Ansible 2.4
ansible-playbook --ask-vault-pass site.yml


  • To prompt for a vault id password:

ansible-playbook --vault-id @prompt site.yml

4.3.3 - executable script

To get the password from a vault password executable script

ansible-playbook --vault-id

5 - Support

5.1 - ERROR! Decryption failed (no vault secrets were found that could decrypt) on - for -

Your vault passphrase is not the good one.

6 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap