Ansible - Encrypt a property (password, private key)

Card Puncher Data Processing


How to encrypt a string property with ansible-vault

If you want to decrypt it back, see Ansible - Decrypt a property (password, private key)


From a literal

  • In line String
ansible-vault encrypt_string [--prompt] [options] string_to_encrypt

From a file

  • String from a File content
cat file | ansible-vault encrypt_string [--prompt] [options] 

You can encrypt a private key this way for instance.


With a executable passwordFile and without label

  • First create a file that will store the Ansible vault passphrase
#!/usr/bin/env bash
echo myVaultPassord
  • Encrypt with a Vault Id which is here only a password and no label
ansible-vault encrypt_string --vault-id 'password' 
# If you want to have the property name in the output, you can add it as parameter
# --name 'property_name'
property_name: !vault |
Encryption successful

With a executable password file and with label

With a executable password file and with vault label

#!/usr/bin/env bash
echo myVaultPassword
  • With the label dev for instance
ansible-vault encrypt_string --vault-id [email protected] 'foobar' --name 'the_secret'
  • In the value, we can see the dev label coming back.
the_secret: !vault |

Discover More
Card Puncher Data Processing
Ansible - Ansible-vault

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: password private keys ...
Card Puncher Data Processing
Ansible - Decrypt a property (password, private key)

How to decrypt a property that was previously encrypted . Inline Copy the string in a file and use it as input
Card Puncher Data Processing
Ansible - Password

in Ansible Lookup password - Create a random password and store it in a file See
Card Puncher Data Processing
Ansible - Vault

A vault is the encrypted format of data through the combination of a label and a password known as vault id Encrypted data may be: a whole file or a property value This is available since Ansible...
Card Puncher Data Processing
How to perform File System operations (copy, exists, move, ) in Ansible?

This page shows you how to perform File system operations in Ansible. When looping through files, you can get the...

Share this page:
Follow us:
Task Runner