how do i copy files and sub folders recursively from one location to another location on remote machine by using ansible

0 votes
[web]
server1
server2
main.yaml
- hosts: web
tasks:
- name: copy files on remote machine
  synchronize:
   src: /home/anil/anilfolder/
dest: /home/anil/anilbackup/
delegate_to:  "{{ inventory_hostname }}"

i wrote like above. but sometime i got synchronizes error. is any other alternative way to copy files and folders from one location to another location on remote machine.please give the solution as soon as possible

Jun 24, 2019 in Ansible by anil

edited Jun 24, 2019 by Kalgi 1,113 views
You're trying to copy a folder from one location to another right? You can achieve the same without using synchronize.
please give  one example if it has another solution

1 answer to this question.

0 votes

Try this:

- hosts: web
  tasks:
  - name: Ansible copy files from a directory to remote server
    copy:
      src:/home/anil/anilfolder/
      dest:/home/anil/anilbackup/
answered Jun 24, 2019 by Kalgi
• 52,350 points
by using above playbook,copy the files from source server to destination server.

but my requirement is copy files from one folder to another folder on remote server.

Hi,

Then you can add "remote_src=yes"(this will executive in remote node) to the below play

- hosts: web
  tasks:
  - name: Ansible copy files from a directory to remote server
    copy:
      src:/home/anil/anilfolder/
      dest:/home/anil/anilbackup/
Thanks, @vivek. I'll try this out.

Related Questions In Ansible

0 votes
1 answer

Ansible playbbok to copy files from one node to another remote node

You can create a playbook for copying ...READ MORE

answered Jan 16, 2019 in Ansible by Danica
2,669 views
0 votes
1 answer

Ansible playbook for moving files from one node to another remote node

The best way to do this is: copy ...READ MORE

answered Jan 16, 2019 in Ansible by Nigya

edited Jan 18, 2019 by Vardhan 7,846 views
0 votes
1 answer

How to copy files in remote system using Ansible?

Hi@akhtar, You need to use the copy module ...READ MORE

answered Jul 30, 2020 in Ansible by MD
• 95,340 points
438 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,588 views
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP