Created
December 22, 2016 11:35
-
-
Save alces/211c725c6d2df0e4083b17076ff4dd8e to your computer and use it in GitHub Desktop.
Ansible playbook copying content of a remote directory to another recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Recursive copy | |
hosts: all | |
vars: | |
my_src: /path/to/src/dir | |
my_dst: /path/to/dst/dir | |
tasks: | |
- name: find dirs | |
find: | |
paths: "{{ my_src }}" | |
file_type: directory | |
recurse: yes | |
register: dirs_list | |
- name: make directories | |
file: | |
name: "{{ item.path.replace(my_src, my_dst) }}" | |
state: directory | |
with_items: "{{ dirs_list.files }}" | |
- name: find files | |
find: | |
paths: "{{ my_src }}" | |
recurse: yes | |
register: files_list | |
- name: copy files | |
copy: | |
src: "{{ item.path }}" | |
dest: "{{ item.path.replace(my_src, my_dst) }}" | |
remote_src: yes | |
with_items: "{{ files_list.files }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment