$linuxjunkies
>

ansible-vault(1)

Encrypt and decrypt sensitive data in Ansible playbooks and variable files.

UbuntuDebianFedoraArch

Synopsis

ansible-vault [create|edit|view|encrypt|decrypt|rekey|encrypt_string] [options] file_name

Description

ansible-vault is a tool for encrypting sensitive data in Ansible projects, such as passwords, API keys, and credentials. It uses AES-256 encryption to protect content while keeping files readable to Ansible during playbook execution.

Vault works by prompting for a password that encrypts/decrypts files. The same password is required to run playbooks containing encrypted content. You can manage multiple vault passwords and encrypt individual strings rather than entire files.

Common options

FlagWhat it does
createCreate a new encrypted file; prompts for vault password
editEdit an encrypted file; decrypts temporarily, re-encrypts on save
viewDisplay encrypted file contents without editing
encryptEncrypt an existing plaintext file
decryptPermanently decrypt a file to plaintext
encrypt_stringEncrypt a string value for use in playbooks
--vault-password-file FILERead vault password from file instead of prompting
--vault-id ID@FILEUse specific vault identity with password from file
-p, --promptPrompt for vault password (default behavior)
--new-vault-password-file FILEUse new password file when rekeying
--output FILEWrite encrypted output to file (for encrypt_string)

Examples

Create a new encrypted file, prompts for password, opens in editor

ansible-vault create secrets.yml

Decrypt and edit existing vault file, automatically re-encrypts on save

ansible-vault edit secrets.yml

Display encrypted file contents without opening in editor

ansible-vault view secrets.yml

Encrypt an existing plaintext YAML file

ansible-vault encrypt vars.yml

Permanently decrypt a vault file back to plaintext

ansible-vault decrypt secrets.yml

Encrypt a single string value; outputs encrypted format ready for YAML

ansible-vault encrypt_string 'mypassword' --name 'db_password'

Change the password protecting a vault file

ansible-vault rekey secrets.yml

Run playbook with encrypted files using password from file (non-interactive)

ansible-playbook playbook.yml --vault-password-file ~/.vault_pass

Related commands