Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible prompts password when using synchronize

I'm using ansible in the following way:

ansible-playbook -f 1 my-play-book.yaml --ask-pass --ask-sudo-pass

After this I'm asked to enter the ssh & sudo passwords (same password for both).

Inside my playbook file I'm using synchronize task:

synchronize: mode=push src=rel/path/myfolder/ dest=/abs/path/myfolder/

For each host, I'm prompted to enter the ssh password of the remote host (the same that I entered in the beginning of the playbook run)

How can I avoid entering the password when executing synchronize task?

like image 294
Mizh Avatar asked Jul 01 '14 07:07

Mizh


People also ask

Why doesn’t Ansible synchronize work on the local host?

In Ansible 2.0 a bug in the synchronize module made become occur on the “local host”. This was fixed in Ansible 2.0.1. Currently, synchronize is limited to elevating permissions via passwordless sudo. This is because rsync itself is connecting to the remote machine and rsync doesn’t give us a way to pass sudo credentials in.

What if Ansible doesn’t know the password?

This happens when Ansible needs to run some command with sudo but it doesn’t know the password. In this note i will show how to make the ansible-playbook command prompt for a password at a runtime and how to pass the password non-interactively during automated deployment.

What does Sudo password is required mean in Ansible?

If you run an Ansible task that requires a privilege escalation, i.e. with become: true, you may get an error “sudo: a password is required”. This happens when Ansible needs to run some command with sudo but it doesn’t know the password.

What SSH configuration does Ansible use?

In Ansible 2.11 and onwards, when set to true, it uses all SSH connection configurations like ansible_ssh_args, ansible_ssh_common_args, and ansible_ssh_extra_args. Verify destination host key. rsync must be installed on both the local and remote host.


1 Answers

If you have setup the ssh keys correctly on the <host>, then the following should work.

ansible all -m synchronize -a "mode=push src=rel/path/myfolder/ dest=/abs/path/myfolder/" -i <host>, -vvv

I was able to get the above working without any password prompt.

like image 89
akh Avatar answered Oct 03 '22 15:10

akh