I wish to copy all files
from
localhost IP(10.8.33.44) folder location: /app/tmpfiles/
to multiple destination IPs with user id user2 at location /app/IBM/profiles/backup/54166/
I run the playbook from localhost IP(10.8.33.44) with user id user1.
I’m using synchronize module to do this. I use delegate_to: localhost so that the files from copied from local src only.
Below is my playbook:
`
-
name: “Play 3”
hosts: dest_nodes
any_errors_fatal: True
user: user2 -
name: “Backup of files on Destination Server {{ inventory_hostname }}.”
synchronize:
src: “{{ playbook_dir }}/tmpfiles/”
dest: “{{ vars[inventory_hostname] }}/{{ Relative_Path }}/backup/{{ Number }}/”
mode: push
delegate_to: localhost
`
The issue occurs in copy when the host and destination are the same i.e localhost IP(10.8.33.44)
The playbook run fails due to permission issue because rsync command constructed by ansible is incorrect and is trying to copy files as user1 on destination server instead of user2.
Below is the error log:
TASK [Backup of files on Destination Server 10.8.33.44.] ***
fatal: [10.8.33.44 → localhost]: FAILED! => {“changed”: false, “cmd”: “/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --out-format=<>%i %n%L /app/tmpfiles/ user1@10.8.33.44:/was/IBM/profiles/backup/54166/”, “msg”: “Warning: Permanently added ‘10.8.33.44’ (ECDSA) to the list of known hosts.\r\nrsync: ERROR: cannot stat destination "/was/IBM/profiles/backup/54166/": Permission denied (13)\nrsync error: errors selecting input/output files, dirs (code 3) at main.c(635) [Receiver=3.1.2]\n”, “rc”: 3}
Can you please help me with a solution to this ?