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?

2 Answers 2

6

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

1
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
1
  • Does not answer the question but is exactly what I was looking for!
    – cdauth
    Feb 14, 2022 at 0:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .