I have the following ansible role:
- name: Get latest code from repository
git:
repo: 'https://{{ username }}:{{ password }}@{{ repository }}'
dest: "{{ destination }}"
force: yes
While username
and repository
can be variables, I am puzzled over how to retrieve password
from ansible vault. Any advice and insight is appreciated.
First, create a YAML file in
vars/
folder (it can be in any folder,host_vars
orgroup_vars
are also valid, depending of what type of variables you're keeping) containing your variables. Let's call itvars/git-data.yml
. Then, encrypt it using Vault with:A password will be required. Remember it.
Then, you have two options for including your variables while running your playbook:
ansible-playbook
:Vault's password will be asked. You can also use
--vault-password-file ${file}
orANSIBLE_VAULT_PASSWORD_FILE
environment variable indicating a password containing a password file.Best regards.