Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible Vault Password File Not Being Found #41

Closed
bdlamprecht opened this issue Dec 5, 2017 · 5 comments · Fixed by #43
Closed

Ansible Vault Password File Not Being Found #41

bdlamprecht opened this issue Dec 5, 2017 · 5 comments · Fixed by #43

Comments

@bdlamprecht
Copy link

I had a "basic" installation of Ansible 2.4.0 installed on a VM which I did all of my development for a proof-of-concept on.

Now, I'm trying to move that proof-of-concept environment into a docker container, but am running into issues when using ansible-silo with ansible-vault. Is that a supported feature?

Let me explain my setup a little further. I have some files which I encrypted that my "basic" ansible setup was able to read due to an environment variable called ANSIBLE_VAULT_PASSWORD_FILE which contained the path to a file that contained the password used to decrypt those files.

Now, after "upgrading" to use ansible-silo and running my playbook, I get the following error:

ERROR! The vault password file /home/[USERNAME]/.ansible_vault_pass was not found

But when I execute the command cat home/[USERNAME]/.ansible_vault_pass, it does in fact exist.

Assuming the problem was that the "data" that ansible-silo uses is now the one created by the installation command (defaulting to silo.[USERNAME]), so I found the location of the volume on my VM (discovered by issuing the command docker volume inspect silo.[USERNAME]) and copied the file .ansible_vault_pass to the /_data/ directory of that volume.

Then I changed the existing envrionment variable ANSIBLE_VAULT_PASSWORD_FILE to be just .ansible_vault_pass instead of /home/[USERNAME]/.ansible_vault_pass and ran it again.

However, the error that I'm getting now is the following:

ERROR! The vault password file /home/user/playbooks/.ansible_vault_pass was not found

I'm not sure where the directory /home/user/playbooks/ is located or if I'm going about this in the entirely wrong fashion?

I'd appreciate any help in solving this or providing an alterntive way to accomplish what I'm trying to do from individuals who designed the internal workings of ansible-silo (Thanks for creating it, BTW).

@udondan
Copy link
Collaborator

udondan commented Dec 7, 2017

Thanks for the report. We'll add support for the ANSIBLE_VAULT_PASSWORD_FILE env var in the next version. The var is forwarded to the container, but the password file is not available inside.

In the meantime you can create a file ~/.ansible-silo or /etc/ansible/ansible-silo/ansible-silo with the following content:

silo_forward_vault_password_file() {
  local vault_password_dir return=""
  if [[ ! -z "${ANSIBLE_VAULT_PASSWORD_FILE}" ]]; then
    vault_password_dir="$(dirname "${ANSIBLE_VAULT_PASSWORD_FILE}")"
    return+="--volume \"${vault_password_dir}\":\"/tmp/${vault_password_dir}:ro\" "
    return+="--env ANSIBLE_VAULT_PASSWORD_FILE='/tmp/${ANSIBLE_VAULT_PASSWORD_FILE}'"
    echo "${return}"
  fi
}

This will mount the location of your password file as a volume into the container and rewrites ANSIBLE_VAULT_PASSWORD_FILE to point to that mounted directory.

You can read here about how Silo extensions like this work.

Let me know if you have further issues with this.

@udondan
Copy link
Collaborator

udondan commented Dec 7, 2017

Github closed this automatically due to #43. Reopening until next version is out.

@udondan udondan reopened this Dec 7, 2017
@bdlamprecht
Copy link
Author

Yeah, adding that file to my home directory solved the problem. Thanks again for the quick resolution.

@udondan
Copy link
Collaborator

udondan commented Jan 8, 2018

Finally a new Silo release is out which includes above snippet. When using Silo v2.0.4 you can remove the ~/.ansible-silo file.

@udondan udondan closed this as completed Jan 8, 2018
@bdlamprecht
Copy link
Author

bdlamprecht commented Jan 8, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants