SCP from ansible server to managed host

20 views
Skip to first unread message

David McPherson

unread,
Oct 10, 2019, 3:02:14 PM10/10/19
to Ansible Project
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

---
- hosts: 'ud-mgmt-srv'
  become: true
  get_info: false
  tasks:
  - name: Check httpdate rpm
    stat: path=/tmp/htpdate-1.1.0-1.el7.rf.x86_64.rpm
    register: st

  - name: Copy httpdate rpm
    command: scp 10.236.1.57:/tmp/htpdate-1.1.0-1.el7.rf.x86_64.rpm /tmp/.
    when: not st.stat.exists

  - name: Install htpdate
    yum:
      name: /tmp/htpdate-1.1.0-1.el7.rf.x86_64.rpm
      state: present

Kai Stian Olstad

unread,
Oct 10, 2019, 3:29:05 PM10/10/19
to ansible...@googlegroups.com
On 10.10.2019 21:02, David McPherson wrote:
> 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'
> become: true
> get_info: false
> tasks:
> - name: Check httpdate rpm
> stat: path=/tmp/htpdate-1.1.0-1.el7.rf.x86_64.rpm
> register: st

This is not needed, copy module handles this.


> - name: Copy httpdate rpm
> command: scp 10.236.1.57:/tmp/htpdate-1.1.0-1.el7.rf.x86_64.rpm
> /tmp/.
> when: not st.stat.exists

- name: Copy httpdate rpm
copy:
src: /tmp/htpdate-1.1.0-1.el7.rf.x86_64.rpm
dest: /tmp


--
Kai Stian Olstad

David McPherson

unread,
Oct 10, 2019, 3:46:10 PM10/10/19
to Ansible Project
Thank you for that clarification.
The copy: mdule works as you described.

Dave
Reply all
Reply to author
Forward
0 new messages