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

The ansible provisioner not longer prompts for the vault password when using ansible 2.4.0.0 with ask_vault_pass set to true. #9033

Closed
IanCaunce opened this issue Oct 5, 2017 · 3 comments

Comments

@IanCaunce
Copy link

The ansible provisioner not longer prompts for the vault password when using ansible 2.4.0.0 with ask_vault_pass set to true.

Vagrant exits with the error:

ERROR! Attempting to decrypt but no vault secrets found
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

After some googleing I found this stackoverflow post.

Tested using vagrant version 1.9.1, 1.9.5 and 2.0.0.
Host OS: Ubuntu 16.04
Kernel: 4.10.0-35-generic
Guest OS: ubuntu/xenial64

Expected Behaviour:

Vagrant should prompt the user for the vault password.

Actual Behaviour:

Vagrant doesn't prompt the user and exits.

Vagrant File

Vagrant.configure(2) do |config|

    box_name = "my-box-name"

    config.vm.define box_name
    config.vm.hostname = box_name

    config.vm.provider "virtualbox" do |v|
        v.name = box_name
        v.memory = 1024
    end

    config.vm.box = "ubuntu/xenial64"

    config.vm.network "forwarded_port", guest: 80, host: 8080
    config.vm.network "forwarded_port", guest: 3306, host: 3306

    config.ssh.forward_agent = true

    config.vm.synced_folder ".", "/vagrant", owner: "ubuntu", group: "www-data", mount_options: ["dmode=775", "fmode=664"]

    config.vm.provision "ansible" do |ansible|
        ansible.extra_vars = {
            ansible_python_interpreter: "/usr/bin/python3"
        }
        ansible.ask_vault_pass = true
        ansible.inventory_path = "provisions/hosts"
        ansible.galaxy_role_file = "provisions/requirements.yml"
        ansible.galaxy_roles_path = "provisions/roles/vendor"
        ansible.playbook = "provisions/playbook.yml"
    end
end
@gildegoma
Copy link
Collaborator

@IanCaunce Thank you for reporting this. As you mentioned, this problem is caused by a change in Ansible 2.4, not in Vagrant.

I am quite unsure that something can be done in Vagrant itself (see similar story in #2924, about the impossibility to handle non-private variable prompts).

This must be reported to Ansible project. I suspect that ansible/ansible#30993 is related to same change (removal of getpass.getpass usage for the password interactive prompt).

See also more details here: https://stackoverflow.com/a/46477011

@IanCaunce
Copy link
Author

After reading that stackoverflow I thought that was the case but wanted to report it here just in case a fix could be applied in vagrant to support ansible's new logic.

Thanks for the feedback!

alikins added a commit to ansible/ansible that referenced this issue Nov 15, 2017
* Fix vault --ask-vault-pass with no tty

2.4.0 added a check for isatty() that would skip setting up interactive
vault password prompts if not running on a tty.

But... getpass.getpass() will fallback to reading from stdin if
it gets that far without a tty. Since 2.4.0 skipped the interactive
prompts / getpass.getpass() in that case, it would never get a chance
to fall back to stdin.

So if 'echo $VAULT_PASSWORD| ansible-playbook --ask-vault-pass site.yml'
was ran without a tty (ie, from a jenkins job or via the vagrant
ansible provisioner) the 2.4 behavior was different than 2.3. 2.4
would never read the password from stdin, resulting in a vault password
error like:

        ERROR! Attempting to decrypt but no vault secrets found

Fix is just to always call the interactive password prompts based
on getpass.getpass() on --ask-vault-pass or --vault-id @prompt and
let getpass sort it out.

* up test_prompt_no_tty to expect prompt with no tty

We do call the PromptSecret class if there is no tty, but
we are back to expecting it to read from stdin in that case.

* Fix logic for when to auto-prompt vault pass

If --ask-vault-pass is used, then pretty much always
prompt.

If it is not used, then prompt if there are no other
vault ids provided and 'auto_prompt==True'.

Fixes vagrant bug hashicorp/vagrant#9033

Fixes #30993
alikins added a commit to ansible/ansible that referenced this issue Nov 15, 2017
* Fix vault --ask-vault-pass with no tty

2.4.0 added a check for isatty() that would skip setting up interactive
vault password prompts if not running on a tty.

But... getpass.getpass() will fallback to reading from stdin if
it gets that far without a tty. Since 2.4.0 skipped the interactive
prompts / getpass.getpass() in that case, it would never get a chance
to fall back to stdin.

So if 'echo $VAULT_PASSWORD| ansible-playbook --ask-vault-pass site.yml'
was ran without a tty (ie, from a jenkins job or via the vagrant
ansible provisioner) the 2.4 behavior was different than 2.3. 2.4
would never read the password from stdin, resulting in a vault password
error like:

        ERROR! Attempting to decrypt but no vault secrets found

Fix is just to always call the interactive password prompts based
on getpass.getpass() on --ask-vault-pass or --vault-id @prompt and
let getpass sort it out.

* up test_prompt_no_tty to expect prompt with no tty

We do call the PromptSecret class if there is no tty, but
we are back to expecting it to read from stdin in that case.

* Fix logic for when to auto-prompt vault pass

If --ask-vault-pass is used, then pretty much always
prompt.

If it is not used, then prompt if there are no other
vault ids provided and 'auto_prompt==True'.

Fixes vagrant bug hashicorp/vagrant#9033

Fixes #30993

(cherry picked from commit 86dc3c0)
@ghost
Copy link

ghost commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants