Giter Club home page Giter Club logo

ansible-dircopy's Introduction

Ansible module: fast recursive copy

It is custom Ansible module for copying directories recursively and fast.  
The module intends to solve the old problem with the core copy module: it is useless useable (after some fixing introduced in 2.4) but still very slow with lots of files. As the Ansible documentation states about the copy module:

The “copy” module recursively copy facility does not scale to lots (>hundreds) of files.

Using synchronize instead of it may be inconvenient in many cases. This module (at least) ten times faster than the 'official' copy.

Additionally this module can handle tar archives; extract or update remote files/dirs from local tar archive.

Options:

parameter required default choices comments
dest yes Remote absolute path where the file should be copied to. This must be a directory. If dest is a nonexistent path, dest is created. The parent directory of dest isn't created: the task fails if it doesn't already exist.
group no Name or GID of the group that should own the file/directory, as would be fed to chown.
gzip no no yes/no Compress data on transferring (applicable when src is a directory)
idenctical no no yes/no If yes, it will delete all files and dirs which are not in the source. (Makes an 'identical' copy.) Alias: delete
mode no Mode the file or directory should be. For those used to /usr/bin/chmod remember that modes are actually octal numbers (like 0644 or 740).
owner no Name or the UID of the user that should own the file/directory, as would be fed to chown.
specialx no no yes/no If yes, set executable flags to the directories for all users have any right to the directories (eg. if mode=640, it will be 750 for directories)
src yes Local path to a directory to copy to the remote server; can be absolute or relative - it is copied recursively. If src is a tar archive its content will be copied.
verbose no yes yes/no If yes, it provides detailed information about the differences between src and dest (running the module in verbose mode (-v))
Run-example:

dircopy_test.yml:

---
- hosts: test.ho.st
  tasks:
  - name: Dircopy (custom module)
    dircopy: src=/opt/tmp/go/ dest=/opt/dc_test owner=jboss group=jboss mode=0640 delete=yes verbose=true
  - name: Ansible copy (core module)
    copy: src=/opt/tmp/go/  dest=/opt/copy_test owner=jboss group=jboss mode=0640

  become: yes
  become_user: root
  become_method: sudo

Out:

$  ansible-playbook -i inv dircopy_test.yml --user ansible --ask-pass --ask-sudo-pass -v
Using /etc/ansible/ansible.cfg as config file
SSH password:
SUDO password[defaults to SSH password]:

PLAY [test.ho.st] ***********************************************

TASK [setup] *******************************************************************
Tuesday 12 September 2017  11:53:34 +0200 (0:00:00.056)       0:00:00.056 *****
ok: [test.ho.st]

TASK [Ansible copy (core module)] **********************************************
Tuesday 12 September 2017  11:53:35 +0200 (0:00:00.940)       0:00:00.996 *****
changed: [test.ho.st] => {
    "changed": true,
    "dest": "/opt/copy_test/",
    "src": "/opt/tmp/go/misc"
}

TASK [Dircopy test (custom)] ***************************************************
Tuesday 12 September 2017  12:02:49 +0200 (0:09:14.353)       0:09:15.349 *****
changed: [test.ho.st] => {
    "changed": true,
    "msg": "/opt/tmp/go/misc copied to /opt/dc_test/ "
}

PLAY RECAP *********************************************************************
test.ho.st:  ok=3    changed=2    unreachable=0    failed=0

Tuesday 12 September 2017  12:02:50 +0200 (0:00:01.344)       0:09:16.694 *****
===============================================================================
Ansible copy (core module) -------------------------------------------- 554.35s
Dircopy test (custom module) -------------------------------------------- 1.34s
setup ------------------------------------------------------------------- 0.94s

(tasks' runtime data with profile_tasks)

Limitations:
  • won't work on windows
  • not tested with SElinux
  • ...

ansible-dircopy's People

Contributors

namondo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.