Hi Glen,

You may use copy and fetch module as shown below:
In  the below playbook the files would be fetch from source machine and 
stored temporarily on the control node and then copied to the destination. 

---
 - hosts: src_apps
   tasks:
     - name: List of files to be copied
       command: "find /opt/dummyfiles/ -type f"
       register: list_files

     - name: Fetch the file from the source to control node
       run_once: yes
       fetch: src={{item}} dest=buffer/ flat=yes
       with_items: "{{ list_files.stdout_lines }}"

 - hosts: dest_apps
   tasks:
     - name: Copy the file from control node to destination
       copy: src=buffer/ dest=/opt/


OR

If you do not want to use the control node to store the files, you may use 
the command module and execute the SCP command from the source machine 
itself. Below is the playbook:
Please note, before executing the playbook you would need to enable 
password-less SSH between the two remote nodes. 
---
 - hosts: src_apps
   tasks:
     - name: List of files to be copied
       command: "find /opt/dummyfiles/ -type f"
       register: list_files

     - name: Execute SCP command
       command: scp -r {{item}} ServerB:/destination
       with_items: "{{ list_files.stdout_lines }}"


Hope this is helpful !

Best Regards,
Shivharsh

On Wednesday, 1 May 2019 06:40:26 UTC+5:30, Glen Collins wrote:
>
> Hello all!
>
>    I have an issue in my environment where I cannot use the synchronize 
> module to transfer data between two remote nodes. So I need a different way 
> to do this.
>
> ServerA: Ansible Server (Tower Instance)
> ServerA1: Ansible Server (Tower Instance)
> ServerA2: Ansible Server (Tower Instance)
>
> ServerB: Data Server
>
> ServerC: User Server
>
> I want to run a playbook on ServerA and have it copy a/many file(s) from 
> ServerB to ServerC. I cannot use synchronize do to environmental issues. So 
> how can I get this done ether using copy or fetch modules. Or something 
> else like SCP from the shell or command module.
>
> I cannot find a good example of doing this other than the synchronize 
> module. I do not want to just copy the data files to the tower servers. I 
> need to keep my environment the same as it is today without changes.
>
> I'm using ansible 2.7. These are all Redhat Linux Servers.
>
> Here is a sample I tried. Really simple but...Inventory comes from tower 
> server which is why the hosts says "all"
>
> ---
> - name: Playbook1
>   hosts: all
>   gather_facts: yes
>   become: yes
>   remote_user: user1
>
>   tasks:
>
>     - name: Copy file to dest server
>       fetch:
>         src: "/var/tmp/file1"
>         dest: "/var/tmp/"
>         flat: yes
>       delegate_to: ServerB
>     
> ---
> - name: Playbook2
>   hosts: all
>   gather_facts: yes
>   become: yes
>   remote_user: user1
>
>   tasks:
>
>     - name: Copy file to dest server
>       copy:
>         src: "/var/tmp/file1"
>         dest: "/var/tmp/"
> remote_src: yes
>       delegate_to: ServerB
>
> Any help would be appreciated.
>
> Regards,
>
> Glen
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/da738150-3379-4560-8e93-bf84568a0522%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to