Ashar
Ashar

Reputation: 3245

Ansible fails to push local files to target server using rsync

Using Ansible, I wish to transfer all files from redhat localhost /app/tmpfiles/ folder to remoteaixhost at location /was/IBM/BACKUP/00005/ with current timestamp and 755 permissions

Below command shows that I do have a file on my localhost:

[localuser@localhost]$ ls -ltr /app/tmpfiles/*
-rw-rw-r-- 1 localuser user 12 Sep 13 15:53 /app/tmpfiles/testingjsp4.jsp

Below is my ansible playbook for this task.

- name: Play 1
  host: remoteaixhost
   - name: "Backup on Destination Server"
     tags: validate
     local_action: command rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "--out-format=<<CHANGED>>%i %n%L" "{{ playbook_dir }}/tmpfiles/*" "{{ USER }}@{{ inventory_hostname }}":"{{ vars[inventory_hostname] }}/BACKUP/{{ Number }}/"
     run_once: true

Running the above playbook fails and below are the error log from ansible:

TASK [Backup on Destination Server remoteaixhost.] *** fatal: [remoteaixhost -> localhost]: FAILED! => {"changed": true, "cmd": ["rsync", "--delay-updates", "-F", "--compress", "--chmod=755", "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null", "--out-format=<>%i %n%L", "/app/tmpfiles/", "user2@remoteaixhost:/was/IBM/BACKUP/00005/"], "delta": "0:00:00.228097", "end": "2019-10-04 00:23:09.103525", "msg": "non-zero return code", "rc": 23, "start": "2019-10-04 00:23:08.875428", "stderr": "Warning: Permanently added 'remoteaixhost' (RSA) to the list of known hosts.\r\nThis system is for the use of authorized users only. Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel. In the course of monitoring individuals improperly using this system, or in the course of system maintenance, the activities of authorized users may also be monitored. Anyone using this system expressly consents to such monitoring and is advised that if such such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to the law enforcement officials\nrsync: link_stat \"/app/tmpfiles/\" failed: No such file or directory (2)\nrsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]", "stderr_lines": ["Warning: Permanently added 'remoteaixhost' (RSA) to the list of known hosts.", "This system is for the use of authorized users only. Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel. In the course of monitoring individuals improperly using this system, or in the course of system maintenance, the activities of authorized users may also be monitored. Anyone using this system expressly consents to such monitoring and is advised that if such such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to the law enforcement officials", "rsync: link_stat \"/app/tmpfiles/*\" failed: No such file or directory (2)", "rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]"], "stdout": "", "stdout_lines": []}

NO MORE HOSTS LEFT


PLAY RECAP ********************************************************************* remoteaixhost : ok=8 changed=4 unreachable=0
failed=1 skipped=6 rescued=0 ignored=0 localhost
: ok=4 changed=2 unreachable=0 failed=0 skipped=1
rescued=0 ignored=0

Build step 'Execute shell' marked build as failure Finished: FAILURE

One thing that bothers me in the output is "fatal: [remoteaixhost -> localhost]" .Why does it say "remoteaixhost -> localhost" when we are actually specifying local_action and I was expecting it to show like this: "localhost -> remoteaixhost" However, I m not sure if my observation is concerning, what the solution is and if this helps us look in the right direction.

Note: I also tried removing the astrick from the rsync command above like below:

rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "--out-format=<<CHANGED>>%i %n%L" "{{ playbook_dir }}/tmpfiles/" "{{ USER }}@{{ inventory_hostname }}":"{{ vars[inventory_hostname] }}/BACKUP/{{ Number }}/"

No errors are received however, the file/s does not get copied to the target host.

I tried to run manually the rsync command on localhost as generated by the ansible and below is the observation:

# with aistrick the copy is successful:

[localuser@localhost]$ rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --out-format="<<CHANGED>>%i %n%L" /app/tmpfiles/* user2@remoteaixhost:/was/IBM/BACKUP/00005/
Warning: Permanently added 'remoteaixhost' (RSA) to the list of known hosts.
This system is for the use of authorized users only. Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel. In the course of monitoring individuals improperly using this system, or in the course of system maintenance, the activities of authorized users may also be monitored. Anyone using this system expressly consents to such monitoring and is advised that if such such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to the law enforcement officials
<<CHANGED>><f+++++++++ testingjsp4.jsp
[localuser@localhost]$ echo $?
0

# without aistrick the files do not get copied over:

[localuser@localhost]$ rsync --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --out-format="<<CHANGED>>%i %n%L" /app/tmpfiles/ user2@remoteaixhost:/was/IBM/BACKUP/00005/
Warning: Permanently added 'remoteaixhost' (RSA) to the list of known hosts.
This system is for the use of authorized users only. Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel. In the course of monitoring individuals improperly using this system, or in the course of system maintenance, the activities of authorized users may also be monitored. Anyone using this system expressly consents to such monitoring and is advised that if such such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to the law enforcement officials
skipping directory .
[localuser@localhost]$ echo $?
0

Can you please suggest ?

Upvotes: 0

Views: 1223

Answers (1)

Ashar
Ashar

Reputation: 3245

local_action: command rsync -r --delay-updates -F --compress --chmod=755 "--rsh=/usr/bin/ssh -S none -i /app/my_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" "--out-format=<<CHANGED>>%i %n%L" {{ playbook_dir }}/tmpfiles/*.log "{{ USER }}@{{ inventory_hostname }}":"{{ vars[inventory_hostname] }}/BACKUP/{{ Number }}/"

This works and I have removed the double quotes around -> {{ playbook_dir }}/tmpfiles/*.log

Upvotes: -1

Related Questions