Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy a remote file onto my local machine using Ansible?

Tags:

ansible

I'm using the command module inside my playbook, and it currently looks like this.

- hosts: all

  tasks:   
   - name: Update tar file
     command: sudo scp -r username@hostname:/path/from/destination /path/to/destination

I've omitted the tasks the take place before this task for the purpose of readability, but what happens when I run this playbook is that it stop at this task. It simply doesn't move forward. I'm sure this is because sudo, so It may want the password for that. I'm not sure how to fix that however.

like image 446
Mustaf.Ahmed Avatar asked Jun 16 '17 16:06

Mustaf.Ahmed


1 Answers

You want to use the fetch module.

- hosts: host.example.com
  tasks:
    # Copy remote file (host.example.com:/tmp/somefile) into
    # /tmp/fetched/host.example.com/tmp/somefile on local machine
    - fetch:
        src: /tmp/somefile
        dest: /tmp/fetched
like image 111
Garrett Hyde Avatar answered Sep 21 '22 19:09

Garrett Hyde