Skip to content

Ansible: copy a directory recursive - take two

Another slow attempt at copying directories and files on a remote system from one place to another, using just Ansible operations.

 

This time I'm not using "with_filetree", but building the tree beforehand, using the "find" module:

- name: Find entries
  find:
    path: /path/to/source/directory
    recurse: yes
    file_type: any
  register: source_tree

Afterwards the operation is split into two parts. First create all directories:

- name: Create the directories
  file:
    path: "{{ item.path | regex_replace('/path/to/source/directory/','/path/to/destination/directory/') }}"
    state: directory
    mode: "{{ item.mode }}"
  loop: "{{ source_tree.files | flatten(levels=1) }}"
  loop_control:
    label: "{{ item.path | regex_replace('/path/to/source/directory', '') }}"
  when:
    - item.isdir

The performance of this task is not too bad, but not fast either. The second step is copying all the files:

- name: Copy the files
  copy:
    src: "{{ item.path }}"
    dest: "{{ item.path | regex_replace('/path/to/source/directory/','/path/to/destination/directory/') }}"
    remote_src: yes
    mode: "{{ item.mode }}"
  loop: "{{ source_tree.files | flatten(levels=1) }}"
  loop_control:
    label: "{{ item.path | regex_replace('/path/to/source/directory', '') }}"
  when:
    - item.isdir == False

This task is really slow, needs between 1-2 seconds per file. Just documenting this here, and probably moving on to call "rsync" directly.

  • Twitter
  • Bookmark Ansible: copy a directory recursive - take two at del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • Digg Ansible: copy a directory recursive - take two
  • Bloglines Ansible: copy a directory recursive - take two
  • Technorati Ansible: copy a directory recursive - take two
  • Fark this: Ansible: copy a directory recursive - take two
  • Bookmark Ansible: copy a directory recursive - take two at YahooMyWeb
  • Bookmark Ansible: copy a directory recursive - take two at Furl.net
  • Bookmark Ansible: copy a directory recursive - take two at reddit.com
  • Bookmark Ansible: copy a directory recursive - take two at blinklist.com
  • Bookmark Ansible: copy a directory recursive - take two at Spurl.net
  • Bookmark Ansible: copy a directory recursive - take two at Simpy.com
  • Bookmark Ansible: copy a directory recursive - take two at blogmarks
  • Bookmark Ansible: copy a directory recursive - take two with wists
  • wong it!
  • Bookmark using any bookmark manager!
  • Stumble It!
  • Identi.ca

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options