Skip to content

Instantly share code, notes, and snippets.

@shawnsi
Last active March 27, 2024 11:49
Show Gist options
  • Save shawnsi/b13f6a740bddc670e633 to your computer and use it in GitHub Desktop.
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
@pyrou
Copy link

pyrou commented Dec 6, 2017

Don't forget to make vault-env executable

 chmod +x ~/bin/vault-env

@paulcalabro
Copy link

This is a good idea. Thanks for sharing!

@fullofcaffeine
Copy link

Even better, use secret-tool to store and fetch the password :)

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