# Copy a file from one node to another node

**URL:** <https://forum.ansible.com/t/copy-a-file-from-one-node-to-another-node/34373>\
**Category:** Ansible Project\
**Created:** [December 28, 2020, 3:26pm UTC](https://forum.ansible.com/t/copy-a-file-from-one-node-to-another-node/34373 "2020-12-28T15:26:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [December 28, 2020, 3:26pm UTC](https://forum.ansible.com/t/copy-a-file-from-one-node-to-another-node/34373/1 "2020-12-28T15:26:43Z")

</div>

Let me start this out by saying that this playbook I’m referencing is running on a 3-node Ansible Tower installation. Before anyone says "contact Red Hat’, this question is a base Ansible question, and something that would fall outside of the Red Hat Ansible Tower support chain.

In my playbook, I generate a file on serverA that I want to make sure ends up on Ansible nodeA. Since this is a playbook that could run on any one of 3 servers since its a cluster (nodeA, nodeB, nodeC), using the fetch module could put the file on any one of those 3. So I need to know how to either: 1) specify nodeA specifically when copying the file, or 2) be able to retrieve the execution node and use that.

Here’s the section of my playbook in question:

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [December 28, 2020, 4:16pm UTC](https://forum.ansible.com/t/copy-a-file-from-one-node-to-another-node/34373/2 "2020-12-28T16:16:33Z")

</div>

I was able to get this to work by creating a new Instance Group in Ansible Tower that had the nodeA ansible node as its only member, then assigned this group to the playbook (called a Template in Ansible Tower) which essentially guaranteed that the playbook would always run on that node. Then everything worked as expected.

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [December 28, 2020, 4:19pm UTC](https://forum.ansible.com/t/copy-a-file-from-one-node-to-another-node/34373/3 "2020-12-28T16:19:33Z")

</div>

> Let me start this out by saying that this playbook I'm referencing is running on a 3-node Ansible Tower installation.  
> Before anyone says "contact Red Hat', this question is a base Ansible question, and something that would fall outside of  
> the Red Hat Ansible Tower support chain.
> 
> In my playbook, I generate a file on serverA that I want to make sure ends up on Ansible nodeA. Since this is a  
> playbook that could run on any one of 3 servers since its a cluster (nodeA, nodeB, nodeC), using the fetch module could  
> put the file on any one of those 3. So I need to know how to either: 1) specify nodeA specifically when copying the  
> file, or 2) be able to retrieve the execution node and use that.
> 
> Here's the section of my playbook in question:
> 
> ---  
> - hosts: serverA
> 
> tasks:  
> - name: Write results to file  
> copy:  
> content: " Test message "  
> dest: /home/user1/test.txt  
> owner: user1  
> group: user1
> 
> - name: Copy file to serverB  
> copy:  
> src: "/home/user1/test.txt"  
> dest: "/var/tmp/"  
> delegate\_to: serverB
> 
> Thanks,  
> Harry

Where does the "test message" comes from? A fixed string would be trivial to copy to the target node.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [December 28, 2020, 4:37pm UTC](https://forum.ansible.com/t/copy-a-file-from-one-node-to-another-node/34373/4 "2020-12-28T16:37:46Z")

</div>

I accidentally added that instead of the name of the source file. The source file is created ahead of that using the copy module and the content property. Sorry for the confusion.

Thanks,  
Harry
