Ansible Vault — Managing Secrets Securely in Ansible and AWX — My DevOps Journey By Sireesha
One thing I kept putting off when I started with Ansible was properly securing my secrets. Passwords, API keys, tokens — they were just sitting in plain text inside my vars files. I knew it was wrong but it worked and I kept moving forward. Then I started thinking about what happens when this goes into GitLab. Anyone with access to the repo can see every password. That's when I properly sat down and learned Ansible Vault — and honestly I wish I'd done it from day one. In this blog I'll walk through how I use Ansible Vault from the command line and then how I handle it properly inside AWX so scheduled jobs and workflow templates can still run without someone manually typing a password every time. What is Ansible Vault? Ansible Vault is a built-in feature that lets you encrypt sensitive data — passwords, keys, tokens — so they can be safely stored in your playbooks and pushed to GitLab without exposing anything. The beauty of it is that it works right inside your existing YAML files. Your playbook structure doesn't change — Vault just encrypts the values that need protecting. What I Was Doing Before — The Wrong Way This is what my vars file looked like before Vault: # vars/main.yml ubuntu_sudo_password : MyPassword123 db_password : SuperSecret456 api_token : abcd1234efgh5678 Pushed straight to GitLab. Anyone with repo access could read every single one of those. Not good. Encrypting a Single Value with Ansible Vault The first thing I learned was how to encrypt just a single variable value — not the entire file. This is cleaner because the rest of the vars file stays readable. ansible-vault encrypt_string 'MyPassword123' --name 'ubuntu_sudo_password' It asks you to create a vault password — this is the master password you'll use to decrypt later. Enter it twice: New Vault password: Confirm New Vault password: The output looks like this: ubuntu_sudo_password : !vault | $ANSIBLE_VAULT;1.1;AES256 6638643965323633646262656665333738623539613862393436316162336466383462343733