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.
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
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?
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
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.
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.
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.
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
`