4

There is a directory under /var/test1 with content:

.
..
.git
.gitignore
file1
file2

and I want to copy it on an other location /var/test2 with pre-existing content:

.
..
file1

If I use the Ansible copy:

- copy:
  # note the trailing `/` at `src: /var/test1/` in order to copy the contents
  src: /var/test1/
  dest: /var/test2

it will replace the file1 in the /var/test2

How can I copy the directory contents without replacing the files at the destination?

tvl
  • 369
  • 3
  • 4
  • 10

2 Answers2

6

by default ansible forces overwrites, maybe disabling it would help your case (force=no).

Martynas Saint
  • 1,221
  • 7
  • 15
  • 1
    Why I never saw with option before? lol so dam obvious: http://docs.ansible.com/ansible/copy_module.html Many thanks! – tvl Sep 14 '16 at 13:28
1

You probably want to use synchronize_module. It has delete option:

Delete files in dest that don't exist (after transfer, not before) in the src path. This option requires recursive=yes.

- synchronize:
   src: /var/test1
   dest: /var/test2
   recursive: True
   delete: False
ws6079
  • 103
  • 3
Henrik Pingel
  • 9,380
  • 2
  • 28
  • 39