# synchronize between two remote servers

**URL:** <https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374>\
**Category:** Ansible Project\
**Created:** [January 4, 2019, 6:04pm UTC](https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374 "2019-01-04T18:04:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [January 4, 2019, 6:04pm UTC](https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374/1 "2019-01-04T18:04:38Z")

</div>

I have found other docs on this, but can’t seem to “fix” my issue with what I am finding. Consider the following playbook:

`

- hosts: mybackup  
gather\_facts: false  
vars:  
one\_week: “/devbackup/nonprod\_images/one\_week\_old”  
two\_week: “/devbackup/nonprod\_images/two\_week\_old”  
tasks:  
…
- name: “Retrieve backups from mybackup02”  
synchronize:  
src: /dbbackup/nonprod\_images/\* #\<-- This is on server mybackup  
dest: “rsync://mybackup{{ one\_week }}/”  
mode: push  
archive: yes  
dirs: yes  
perms: yes  
recursive: yes  
times: yes  
rsync\_path: /bin/rsync  
delegate\_to: mybackup02

`

I receive the following failure:

`  
TASK [Retrieve backups from mybackup02] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [mybackup → mybackup02]: FAILED! =\> {“changed”: false, “cmd”: “/usr/bin/rsync --delay-updates -F --compress --archive --dirs --rsync-path=/bin/rsync --out-format=\<\>%i %n%L /dbbackup/nonprod\_images/\* rsync://mybackup/devbackup/nonprod\_images/one\_week\_old/”, “msg”: “rsync: failed to connect to mybackup: Connection refused (111)\nrsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]\n”, “rc”: 10}

`

Probably just need another pair of eyes… I seem to be missing something. SSH keys are setup between the two servers. rsyncs work outside of ansible just fine. I am just trying to move this particular job under tower, so I am converting it from a bash script to a playbook.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 4, 2019, 6:34pm UTC](https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374/2 "2019-01-04T18:34:02Z")

</div>

> I have found other docs on this, but can't seem to "fix" my issue with what  
> I am finding. Consider the following playbook:
> 
> - hosts: mybackup  
> &nbsp;&nbsp;gather\_facts: false  
> &nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;one\_week: "/devbackup/nonprod\_images/one\_week\_old"  
> &nbsp;&nbsp;&nbsp;&nbsp;two\_week: "/devbackup/nonprod\_images/two\_week\_old"  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;...  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: "Retrieve backups from mybackup02"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronize:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /dbbackup/nonprod\_images/\* #\<-- This is on server mybackup  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: "rsync://mybackup{{ one\_week }}/"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mode: push  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;archive: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dirs: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perms: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recursive: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;times: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rsync\_path: /bin/rsync  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: mybackup02

With push mode and delegate\_to src: is mybackup02 and dest is mybackup, based on your comment after src: I guess you need to use pull mode instead.  
But that contradict the text in name: for the task.

Dest can only contain the path, absolute or relative, not rsync://, the module doesn't support rsync protocol, it can only synchronize over ssh.

> Probably just need another pair of eyes... I seem to be missing something.  
> SSH keys are setup between the two servers. rsyncs work outside of ansible  
> just fine.

Are you sure you tested with the user that is running the Ansible playbook?

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [January 4, 2019, 6:39pm UTC](https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374/3 "2019-01-04T18:39:26Z")

</div>

Yes, absolutely positive that I have tested it with the user that is running the ansible playbook.

I am trying to rsync from mybackup02 to mybackup, so the src and destination should be correct.  
According to the docs, the dest can have the rsync. See second and third examples:  
[https://docs.ansible.com/ansible/latest/modules/synchronize\_module.html](https://docs.ansible.com/ansible/latest/modules/synchronize_module.html)

As I understand it, in pull mode you can’t use delegate\_to, and is therefore only good for localhost to remotehost, not remote to remote.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 5, 2019, 5:08pm UTC](https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374/4 "2019-01-05T17:08:02Z")

</div>

I haven't looked at the example, but in the notes section it says  
"Currently there are only a few connection types which support synchronize (ssh, paramiko, local and docker)"  
so I assumed rsync protocol was not supported.

When using the rsync protocol ssh is not needed as the protocol is using port 873.

Ansible is running this command on mybackup02, if you run in manually it works?

/usr/bin/rsync --delay-updates -F --compress --archive --dirs --rsync-path=/bin/rsync --out-format='\<\<CHANGED\>\>%i %n%L' /dbbackup/nonprod\_images/\* rsync://mybackup/devbackup/nonprod\_images/one\_week\_old/

I do see a potential problem with the rsync and that is with the asterisk, in a shell the asterisk will expand them so you might need to add quotes around it.

---

<div class="post-metadata">

**Author:** ![Marcelo\_Roccasalva](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@Marcelo\_Roccasalva](https://forum.ansible.com/u/Marcelo_Roccasalva)\
**Post date:** [January 5, 2019, 5:10pm UTC](https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374/5 "2019-01-05T17:10:37Z")

</div>

I've only looked at the error: rsync: failed to connect to mybackup:  
Connection refused. You don't have an rsync daemon listening on  
mybackup.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [January 7, 2019, 8:02pm UTC](https://forum.ansible.com/t/synchronize-between-two-remote-servers/29374/6 "2019-01-07T20:02:15Z")

</div>

I have it working. Kai was right, I couldn’t use rsync:\. When specifying a delegation all I have to do is specify the correct destination:

working:

`

- name: “Retrieve backups from mybackup02”  
synchronize:  
src: /dbbackup/nonprod\_images/  
dest: “{{ one\_week }}/” #\<— Destination dir on delegated server  
mode: push  
archive: yes  
dirs: yes  
perms: yes  
recursive: yes  
times: yes  
rsync\_path: /usr/bin/rsync  
delegate\_to: mybackup02

`
