Getting rsync in Ansible to work with Vagrant
ansible, rsync, vagrant
Solution
Mark,
If you did not deploy your ssh public key to the box (in `/home/vagrant/ssh/authorized_keys`), it's quite a normal behavior to get asked for a password. Using 'vagrant' with standard boxes should work.
If you push your key first, it would be easier to get things done after. You can find a Vagrant oriented example here
It seems you set `ansible_ssh_user` properly, but make sure you also invoke your playbook with `--ask-pass --sudo`.
As a side note, the line:
when: "{{ item.custom }} == True"
could be rewritten as:
when: item.custom
Problem
I want to test an Ansible script using Vagrant. Everything works fine until it tries to do a rsync to the remote host: ``` - name: Install custom dev user settings local_action: command rsync -ave ssh roles/common/files/home/{{ item.name }} {{ ansible_ssh_user }}@{{ inventory_hostname }}:/#home/ with_items: dev_users when: "{{ item.custom }} == True" tags: - dev_custom - dev_users - users ``` However it fails at this point - it seems to be trying to login via password but I don't know why as it should connect to Vagrant via SSH, right (I have elided some information below with ... because it mentioned keys) ? ``` 127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-1393178896.64-215542007508316 && chmod a+rx $HOME/.ansible/tmp/ansible-1393178896.64-215542007508316 && echo $HOME/.ansible/tmp/ansible-1393178896.64-215542007508316'] <127.0.0.1> REMOTE_MODULE command rsync -ave ssh roles/common/files/home/someUser vagrant@10.0.0.10:/#home/ <127.0.0.1> PUT /tmp/tmpm3BnEW TO /home/mark/.ansible/tmp/ansible-1393178896.64-215542007508316/command <127.0.0.1> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=...] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-...; /usr/bin/python /home/mark/.ansible/tmp/ansible-1393178896.64-215542007508316/command; rm -rf /home/mark/.ansible/tmp/ansible-1393178896.64-215542007508316/ >/dev/null 2>&1'"'"'' failed: [10.0.0.10] => (item={ ... }) => {"failed": true, "item": { ... }, "parsed": false} invalid output was: [sudo via ansible, key=...] password: [sudo via ansible, key=...] password: Sorry, try again. [sudo via ansible, key=...] password: [sudo via ansible, key=...] password: Sorry, try again. [sudo via ansible, key=...] password: [sudo via ansible, key=...] password: Sorry, try again. sudo: 3 incorrect password attempts ``` Any idea how to get around this? I do deploy a custom key to the box via ansible before I do this e.g.: ``` - name: Place ansible authorized key authorized_key: user=root key="{{ lookup('file', 'root/.ssh/ansible_key.pub') }}" tags: - root ```