Open Gnitset opened 5 years ago
I came across this issue today myself with a pretty basic vagrant ansible setup and had a quick look.
I think this could easily be changed by moving the candling of ask_become_pass
from a command argument into an environment variable as @Gnitset suggested.
From this into something like this:
...
@command_arguments << "--ask-vault-pass" if config.ask_vault_pass
prepare_common_command_arguments
end
def prepare_environment_variables
prepare_common_environment_variables
# Some Ansible options must be passed as environment variables,
# as there is no equivalent command line arguments
@environment_variables["ANSIBLE_HOST_KEY_CHECKING"] = "#{config.host_key_checking}"
@environment_variables["ANSIBLE_BECOME_ASK_PASS"] = "#{config.ask_become_pass}"
# ANSIBLE_SSH_ARGS is required for Multiple SSH keys, SSH forwarding and custom SSH settings
@environment_variables["ANSIBLE_SSH_ARGS"] = ansible_ssh_args unless ansible_ssh_args.empty?
end
...
I'd be happy to create a pull request for this, however I'm unsure if it makes sense.
Both in ansible as well as in vagrant the default value for this setting is false.
However in the specific issue mentioned here, where a custom ansible.cfg
is supplied, the setting from that config would be implicitly overwritten by vagrant when changing to the ANSIBLE_BECOME_ASK_PASS
method, which could lead to confusion in users.
What are others opinions on this? Is it instead possible to pass custom environment variables to the command a provisioner executes in some other way (for ansible playbooks that would be here?
Vagrantfile
ansible.cfg
Expected behavior
When setting ansible.ask_become_pass to false I expect it to tell ansible in a convincing way not not ask for password even if the default is to ask based on its config.
Actual behavior
It asks for SUDO password.
Steps to reproduce
become_ask_pass = True
in ansible.cfgansible.ask_become_pass
to false in the VagrantfileSuggested change
If the setting is being sent to ansible with environment
ANSIBLE_BECOME_ASK_PASS=
instead of the existence of the command line parameter-K
it would work both ways.