Search code examples
ansibleansible-vault

Ansible - Syntax to point a variable to a variable in a vault


Trying to use an ansible-vault to hold a sensitive password, but I can't find the right syntax to retrieve it in a playbook.

The doc mentions (Emphasis mine):

Next, copy all of the sensitive variables over to the vault file and prefix these variables with vault_. You should adjust the variables in the vars file to point to the matching vault_ variables using jinja2 syntax, and ensure that the vault file is vault encrypted.

I created the vault, but I am really not familiar enough with jinja2 within yml to find the right syntax for the vars.yml file.

Anyone can help with the syntax on how to point variable 'X' in the playbook to take the value of the variable "vault_X" that is in the vault file?


Solution

  • Can you not try to use import_vars module to import vars stored in the encrypted file into your playbook? Then in the playbook itself you reference them as you would normally do. You just need to add

    --ask-vault-pass

    when running your playbook.