test/playbook-recursive-copy.yml
3ad61ef3
 ---
 # To run me manually, use: -i "localhost,"
 - hosts: localhost
   connection: local
   gather_facts: no
   vars:
     - testdir: /tmp/ansible-rcopy
     - filesdir: test_recursive_copy/files
   tasks:
 
     #
     # First, regression tests for single-file behavior
     #
 
     - name: "src single file, dest file"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/file1
       register: res
     - command: test -f {{testdir}}/file1
9e197d39
     - command: test "{{res.changed}}" = "True"
3ad61ef3
     - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/file1
       register: res
9e197d39
     - command: test "{{res.changed}}" = "False"
3ad61ef3
 
     - name: "src single file, dest dir w/trailing slash"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/
       register: res
     - command: test -f {{testdir}}/test1
9e197d39
     - command: test "{{res.changed}}" = "True"
3ad61ef3
     - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}/
       register: res
9e197d39
     - command: test "{{res.changed}}" = "False"
3ad61ef3
 
     - name: "src single file, dest dir wo/trailing slash - doesn't behave in sane way"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}
       register: res
     - shell: test -f {{testdir}}/test1
9e197d39
     - command: test "{{res.changed}}" = "True"
3ad61ef3
     - copy: src={{filesdir}}/subdir/subdir2/subdir3/test1 dest={{testdir}}
       register: res
9e197d39
     - command: test "{{res.changed}}" = "False"
3ad61ef3
 
     #
     # Now, test recursive behavior
     #
 
     - name: "src dir w/trailing slash, dest w/trailing slash"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir/ dest={{testdir}}/
       register: res
     - command: test -d {{testdir}}/subdir2
     - command: test -d {{testdir}}/subdir2/subdir3
     - command: test -d {{testdir}}/subdir2/subdir3
     - command: test -f {{testdir}}/subdir2/subdir3/test1
     - command: test -f {{testdir}}/subdir2/subdir3/test2
9e197d39
     - command: test "{{res.changed}}" = "True"
3ad61ef3
     - copy: src={{filesdir}}/subdir/ dest={{testdir}}/
       register: res
9e197d39
     - command: test "{{res.changed}}" = "False"
3ad61ef3
 
     # Expecting the same behavior
     - name: "src dir w/trailing slash, dest wo/trailing slash"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir/ dest={{testdir}}
       register: res
     - command: test -d {{testdir}}/subdir2
     - command: test -d {{testdir}}/subdir2/subdir3
     - command: test -d {{testdir}}/subdir2/subdir3
     - command: test -f {{testdir}}/subdir2/subdir3/test1
     - command: test -f {{testdir}}/subdir2/subdir3/test2
9e197d39
     - command: test "{{res.changed}}" = "True"
3ad61ef3
     - copy: src={{filesdir}}/subdir/ dest={{testdir}}
       register: res
9e197d39
     - command: test "{{res.changed}}" = "False"
3ad61ef3
 
     - name: "src dir wo/trailing slash, dest w/trailing slash"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir dest={{testdir}}/
       register: res
     - command: test -d {{testdir}}/subdir/subdir2
     - command: test -d {{testdir}}/subdir/subdir2/subdir3
     - command: test -d {{testdir}}/subdir/subdir2/subdir3
     - command: test -f {{testdir}}/subdir/subdir2/subdir3/test1
     - command: test -f {{testdir}}/subdir/subdir2/subdir3/test2
9e197d39
     - command: test "{{res.changed}}" = "True"
3ad61ef3
     - copy: src={{filesdir}}/subdir dest={{testdir}}/
       register: res
9e197d39
     - command: test "{{res.changed}}" = "False"
3ad61ef3
 
     # Expecting the same behavior
     - name: "src dir wo/trailing slash, dest wo/trailing slash"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir dest={{testdir}}
       register: res
     - command: test -d {{testdir}}/subdir/subdir2
     - command: test -d {{testdir}}/subdir/subdir2/subdir3
     - command: test -d {{testdir}}/subdir/subdir2/subdir3
     - command: test -f {{testdir}}/subdir/subdir2/subdir3/test1
     - command: test -f {{testdir}}/subdir/subdir2/subdir3/test2
9e197d39
     - command: test "{{res.changed}}" = "True"
3ad61ef3
     - copy: src={{filesdir}}/subdir dest={{testdir}}
       register: res
9e197d39
     - command: test "{{res.changed}}" = "False"
3ad61ef3
 
 
     - name: "Verifying notify handling for recursive files"
       command: rm -rf {{testdir}}
     - file: state=directory dest={{testdir}}
     - copy: src={{filesdir}}/subdir dest={{testdir}}
       notify:
         - files changed
     - meta: flush_handlers
     - command: test -f {{testdir}}/notify_fired
 
     - command: rm {{testdir}}/notify_fired
     - copy: src={{filesdir}}/subdir dest={{testdir}}
       notify:
         - files changed
     - meta: flush_handlers
     - command: test ! -f {{testdir}}/notify_fired
 
   handlers:
     - name: files changed
       command: touch {{testdir}}/notify_fired