I am trying to set-up a simple Ansible playbook to carry out copying files from one location to another location on the same remote host. My local, as well as remote hosts, run CentOS-7.
This is how my inventory file looks like:
centos-server ansible_host=10.1.1.1 ansible_connection=ssh ansible_user=root ansible_ssh_pass=<root password>
I used the copy module initially, however, found that this module only copies a file from local to remote. After a bit of search, I found synchronize module which seems to be the correct one to use.
My simple playbook is as follows:
-
name: sync upstream repository to the local machine
hosts: centos-server
tasks:
-
name: copy repo files to yum.repos
synchronize:
src: /etc/yum.repos.d/repo.backup/
dest: /etc/yum.repos.d/
delegate_to: centos-server
As can be seen, I have some .repo
files in the source directory and trying to copy them to yum.repos.d
directory. The above playbook works without any issues, however, I do need to specify delegate_to
attribute.
As per the example discussed in synchronize, I understand the delegate_to
is required as the file is copied from a remote host that is not defined in hosts:
. While in my case, both source and destination are on the same remote host defined in hosts:
. Without delegate_to
, I get this error:
fatal: [centos-server]: FAILED! => {"changed": false, "cmd": "/bin/rsync --delay-updates -F --compress --dry-run --archive --rsh=/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --out-format=<<CHANGED>>%i %n%L /etc/yum.repos.d/repo.backup/ root@10.1.1.1:/etc/yum.repos.d/", "msg": "Warning: Permanently added '10.1.1.1' (ECDSA) to the list of known hosts.\r\nrsync: change_dir \"/etc/yum.repos.d/repo.backup\" failed: No such file or directory (2)\nrsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]\n", "rc": 23}
Can anyone explain what could be happening here?