FreeKB - Ansible synchronize module (copy files directories)
Ansible - synchronize module (copy files directories)

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

The synchronize module is used to copy files or directories, and is based off of rsync. The copy can be done locally, meaning a file or directory on a system is copied to some other directory on the same system. Or the copy can be done remotely, meaning the file or directory is copied from (pull) or to (push) a remote system.

In this example, the contents of the /tmp/foo directory on the control node (that's your Ansible system) will be copied to /tmp/foo on each managed node.

---
hosts: all
  tasks:
  - name: copy /tmp/foo
    synchronize:
      src: /tmp/foo
      dest: /tmp/foo
...

 

In this example, the /tmp/foo directory on each managed node will be copied to /tmp/foo on server1.example.com. This would be a push (upload / PUT ) operation.

---
hosts: all
  tasks:
  - name: copy /tmp/foo
    synchronize:
      src: /tmp/foo
      dest: rsync://server1.example.com/tmp/foo
...

 

In this example, the /tmp/foo directory server1.example.com will be copied to /tmp/foo on each managed node. This would be a pull (download / GET ) operation.

---
hosts: all
  tasks:
  - name: copy /tmp/foo
    synchronize:
      src: rsync://server1.example.com/tmp/foo
      dest: /tmp/foo
...

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 467fe in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |