Copy files from Local to all Destinations using synchronize module fails.

11 views
Skip to first unread message

Mohtashim S

unread,
Sep 9, 2019, 4:04:28 AM9/9/19
to Ansible Project
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=<<CHANGED>>%i %n%L /app/tmpfiles/ us...@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 ?

Kai Stian Olstad

unread,
Sep 9, 2019, 6:41:07 AM9/9/19
to ansible...@googlegroups.com
On 09.09.2019 10:04, Mohtashim S wrote:
> 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

A play has no option user:
ref
https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html#play

on a play it's called remote_user:

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages