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 538 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
• 51,970 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
1,570 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 4,790 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 in Ansible by MD
• 79,930 points
153 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
813 views
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer