AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible Vault: Encrypt, Decrypt & Manage Secrets (Complete Guide) — Video Tutorial
Complete guide to Ansible Vault. Encrypt files and strings, decrypt secrets, use vault passwords, and manage encrypted variables securely.
What You'll Learn
- How to decrypt an Ansible Vault?
- ansible-vault
- Links
- Playbook
- execution
- before execution
- after execution
- Conclusion
- Ansible Vault Overview
- When to Use Vault
Full Tutorial Content
How to decrypt an Ansible Vault?
From an encrypted file to plaintext using the correct password.
I will show you a live Playbook with some simple Ansible code.
I'm Luca Berton, and welcome to today's episode of Ansible Pilot.
ansible-vault
- Included in Ansible installation
- Ansible Vault
- command line
The `ansible-vault` command is included in every Ansible installation for the most modern operating system.
It is a command line tool so interact with that using your terminal.
Using the `ansible-vault` command, you could perform any Ansible vault operation: encryption, decryption, change of password, etc.
Links
- https://docs.ansible.com/ansible/latest/user_guide/vault.html
Playbook
I will show you how to decrypt an Ansible Vault using the ansible-vault command line utility.
At the beginning of this example, we start with an encrypted Ansible vault, and once we enter the correct password, we obtain a cleartext file.
execution
```bash
$ ansible-vault decrypt encrypted-to-plain.yml
Vault password:
Decryption successful
```
before execution
```bash
$ cat encrypted-to-plain.yml
$ANSIBLE_VAULT;1.1;AES256
65333637643363376438633838346563353666636433613032333663666137613839333564393238
3930333031633134346461303636623937353561643464390a363534383938396336346130653231
34356437363733313638336437343735366362343031663866326135633538373237646537356638
6163373837343332660a323666666534353561656464353033613137333463316534663062643561
34373865636163626163313235393239653539356665373361373939633138373137643264386533
3761646565643732396531313561366364353031373731353839
```
after execution
```bash
$ cat encrypted-to-plain.yml
---
password: mysupersecretpassword
```
Conclusion
Now you know how to decrypt an Ansible Vault.
Ansible Vault Overview
Ansible Vault provides encryption for sensitive data like passwords, API keys, and certificates. It uses **AES-256** encryption, which is the same standard used by banks and governments.
When to Use Vault
- Storing database passwords in `group_vars/`
- Encrypting SSH private keys
- Protecting API tokens and secrets
- Securing cloud credentials (AWS, Azure, GCP)
Decrypt Methods
Method 1: Decrypt entire file
```bash
Interactive password prompt
ansible-vault decrypt secrets.yml
Using a password file
ansible-vault decrypt secrets.yml --vault-password-file=.vault_pass
Using vault ID (Ansible 2.4+)
ansible-vault decrypt secrets.yml --vault-id prod@.vault_pass
```
Method 2: View without decrypting
```bash
View contents without modifying the file
ansible-vault view secrets.yml
Pipe to other commands
ansible-vault view secrets.yml | grep database_password
```
Method 3: Decrypt inline during playbook run
```bash
Ansible automatically decrypts vault files during execution
ansible-playbook playbook.yml --ask-vault-pass
Using password file (for CI/CD)
ansible-playbook playbook.yml --vault-password-file=.vault_pass
```
Method 4: Decrypt single variables
If you encrypted a single variable with `ansible
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 8 min
- Category: installation
Read the full written article: Ansible Vault: Encrypt, Decrypt & Manage Secrets (Complete Guide)
Related Video Tutorials
- Use Ansible Vault in Ansbile Playbook - ansible vault — Learn how to use Ansible Vault to secure sensitive data such as passwords and access keys in your playbooks with practical examples and a live Playbook.
- Ansible terminology - What is an Ansible Playbook? — A step-by-step guide inside the Ansible Playbook anatomy: play, tasks, modules, conditional, loop, handler, variable, list.
- Mastering Ansible-Creator: Simplify Your Ansible Collection Development — Discover how to install and use Ansible-Creator to simplify Ansible Collection development. Enhance your automation projects with this powerful tool and Visual.
- Ansible Vault Error: Fix 'Attempting to Decrypt but No Vault Secrets Found' — How to fix Ansible 'attempting to decrypt but no vault secrets found' error. Configure vault password file, --ask-vault-pass, vault-id.
- Ansible troubleshooting - VMware Unknown error while connecting to vCenter or ESXi — Let’s troubleshoot together the Ansible fatal error “Unknown error while connecting to vCenter or ESXi API, [Errno -2] Name or service not known” to find.
- Deploy Kubernetes Resources with Ansible Playbook — Learn how to deploy Kubernetes resources using Ansible. Follow this guide to create namespaces, pods, and services with an Ansible playbook.