# SCP from ansible server to managed host

**URL:** <https://forum.ansible.com/t/scp-from-ansible-server-to-managed-host/31450>\
**Category:** Ansible Project\
**Created:** [October 10, 2019, 7:02pm UTC](https://forum.ansible.com/t/scp-from-ansible-server-to-managed-host/31450 "2019-10-10T19:02:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_McPherson](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dave_mcpherson/32/6973_2.png) [@Dave\_McPherson](https://forum.ansible.com/u/Dave_McPherson)\
**Post date:** [October 10, 2019, 7:02pm UTC](https://forum.ansible.com/t/scp-from-ansible-server-to-managed-host/31450/1 "2019-10-10T19:02:14Z")

</div>

I am attempting to copy a file from the local ansible server to the managed hosts (oracle linux).  
I would like to push the file out to the different managed hosts because if I call back to the Ansible server from the hosts them I have to login, provide password etc.  
Pushing from the ansible host is easier because the ssl keys have been copied to all the hosts and therefore is passwordless.

I haven’t found another way to do it other than using shell or command, copy seems to be for transfering files within the client file system

I also looked at delegate\_to: but there really wasn’t enough documentation for me to figure out how to make that work.

This is what I have so far but it’s reaching back to the ansible server for the file which requires a login.

Any help would be appreciated.

Dave

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 10, 2019, 7:28pm UTC](https://forum.ansible.com/t/scp-from-ansible-server-to-managed-host/31450/2 "2019-10-10T19:28:53Z")

</div>

> I am attempting to copy a file from the local ansible server to the managed  
> hosts (oracle linux).  
> I would like to push the file out to the different managed hosts because if  
> I call back to the Ansible server from the hosts them I have to login,  
> provide password etc.  
> Pushing from the ansible host is easier because the ssl keys have been  
> copied to all the hosts and therefore is passwordless.
> 
> I haven't found another way to do it other than using shell or command,  
> copy seems to be for transfering files within the client file system

This is exactly what the copy module does, it copy a file from Ansible controller aka localhost to the remote host.  
The only way to transferring files within the client is to set "remote\_src: True" on the copy module.

> This is what I have so far but it's reaching back to the ansible server for  
> the file which requires a login.
> 
> Any help would be appreciated.
> 
> Dave
> 
> ---  
> - hosts: 'ud-mgmt-srv'  
> &nbsp;&nbsp;become: true  
> &nbsp;&nbsp;get\_info: false  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: Check httpdate rpm  
> &nbsp;&nbsp;&nbsp;&nbsp;stat: path=/tmp/htpdate-1.1.0-1.el7.rf.x86\_64.rpm  
> &nbsp;&nbsp;&nbsp;&nbsp;register: st

This is not needed, copy module handles this.

> &nbsp;&nbsp;- name: Copy httpdate rpm  
> &nbsp;&nbsp;&nbsp;&nbsp;command: scp 10.236.1.57:/tmp/htpdate-1.1.0-1.el7.rf.x86\_64.rpm /tmp/.  
> &nbsp;&nbsp;&nbsp;&nbsp;when: not st.stat.exists

&nbsp;&nbsp;&nbsp;- name: Copy httpdate rpm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src: /tmp/htpdate-1.1.0-1.el7.rf.x86\_64.rpm  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /tmp

---

<div class="post-metadata">

**Author:** ![Dave\_McPherson](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dave_mcpherson/32/6973_2.png) [@Dave\_McPherson](https://forum.ansible.com/u/Dave_McPherson)\
**Post date:** [October 10, 2019, 7:46pm UTC](https://forum.ansible.com/t/scp-from-ansible-server-to-managed-host/31450/3 "2019-10-10T19:46:09Z")

</div>

Thank you for that clarification.  
The copy: mdule works as you described.

Dave
