Skip to content

Instantly share code, notes, and snippets.

@shawnsi
Last active December 25, 2025 17:13
Show Gist options
  • Select an option

  • Save shawnsi/b13f6a740bddc670e633 to your computer and use it in GitHub Desktop.

Select an option

Save shawnsi/b13f6a740bddc670e633 to your computer and use it in GitHub Desktop.
Ansible Vault Environment Variable

Ansible Vault Environment Variable

Per http://docs.ansible.com/ansible/playbooks_vault.html you can set an environment variable to use a password file for vault access. We can use this to create an environment variable to hold the password.

Password Script

Copy vault-env from this project to ~/bin. Then add this to your ~/.bashrc:

export ANSIBLE_VAULT_PASSWORD_FILE=~/bin/vault-env

Usage

Now just export your password in your shell as needed. Don't be a douche and put this in your profile though.

export ANSIBLE_VAULT_PASSWORD=<password>
#!/bin/bash
echo $ANSIBLE_VAULT_PASSWORD
@sthames42
Copy link

This may have been true, once, but not any longer. The entire contents of the password file becomes the password used to encrypt. Found this out the hard way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment