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.

Use Ansible Vault in Ansbile Playbook - ansible vault — Video Tutorial

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.

Watch on YouTube · Read the written article

Use Ansible Vault in Ansbile Playbook - ansible vault — Video Tutorial

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.

Watch Video

Watch "Use Ansible Vault in Ansbile Playbook - ansible vault" on YouTube

What You'll Learn

Full Tutorial Content

How to use an Ansible Vault in an Ansible Playbook? How to use an Ansible Vault to Protect Sensitive Data such as passwords, access keys, etc. 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 Ansible Vault is included in every Ansible installation for the most modern operating system. It includes all the software encryption and a handy command line utility (`ansible-vault`) to encrypt, modify, change passwords or decrypt files. The encryption of the Ansible Vault files is strong and relies on the AES256 cipher. Links - https://docs.ansible.com/ansible/latest/user_guide/vault.html Playbook Use Ansible Vault in Ansible Playbook I will show you how to use Ansible Vault in Ansible Playbook to store passwords. This example uses a simple playbook that displays on screen a variable and one Ansible vault to store the variable encrypted on disk. In the real world, you can use the variable with any Ansible module without printing on the screen. code without Vault - playbook_without_vault.yml ```yaml --- - name: Playbook without Vault hosts: all vars: mypassword: mysupersecretpassword tasks: - name: print variable ansible.builtin.debug: var: mypassword ``` execution without Vault ```bash $ ansible-playbook -i inventory playbook_without_vault.yml PLAY [Playbook without Vault] *********************************************************** TASK [Gathering Facts] ****************************************************************** [WARNING]: Platform darwin on host demo.example.com is using the discovered Python interpreter at /opt/homebrew/bin/python3.10, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible- core/2.13/reference_appendices/interpreter_discovery.html for more information. ok: [ demo.example.com] TASK [print variable] ******************************************************************* ok: [ demo.example.com] => { "mypassword": "mysupersecretpassword" } PLAY RECAP ****************************************************************************** demo.example.com : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ``` code with Vault - playbook_with_vault.yml ```bash --- - name: Playbook with Vault hosts: all tasks: - name: include vault ansible.builtin.include_vars: file: mypassword.yml - name: print variable ansible.builtin.debug: var: mypassword ``` - mypassword.yml ```bash $ANSIBLE_VAULT;1.1;AES256 35623739386664386238326639623130343635396432393037383666306431623833666266623730 3431326532383363303333336636366338313730613733360a616466373932623131626632613737 66326237653963613031326464353066346161666265623939643235396563646236613566643230 3630393737373765370a613331363034

About This Tutorial

Read the full written article: Use Ansible Vault in Ansbile Playbook - ansible vault

Topics Covered

Related Video Tutorials