# Keeping directory content in sync

**URL:** <https://forum.ansible.com/t/keeping-directory-content-in-sync/36025>\
**Category:** Ansible Project\
**Created:** [November 22, 2021, 7:59pm UTC](https://forum.ansible.com/t/keeping-directory-content-in-sync/36025 "2021-11-22T19:59:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcpetro](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@jcpetro](https://forum.ansible.com/u/jcpetro)\
**Post date:** [November 22, 2021, 7:59pm UTC](https://forum.ansible.com/t/keeping-directory-content-in-sync/36025/1 "2021-11-22T19:59:33Z")

</div>

I am working on a role for work, and it needs to keep the source directory ( that lives on the ansible controlnode ), and the destination ( lives on teh remote ) in sync. I know that the copy module can keep the changes/additions in sync. I am not so much worried about that part. Where I am getting stuck, is how to handle if we delete a file at the source, and want that delete carried forward to the remote.

Is there a good way to do that, other than stat the files, loop through the variable, and delete anything that doesn’t exist?

Any advice you have here would be much appreciated.

–John

---

<div class="post-metadata">

**Author:** ![rilindo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rilindo/32/357_2.png) [@rilindo](https://forum.ansible.com/u/rilindo)\
**Post date:** [November 22, 2021, 8:08pm UTC](https://forum.ansible.com/t/keeping-directory-content-in-sync/36025/2 "2021-11-22T20:08:55Z")

</div>

Hi John,

Is synchronize an option?

[https://docs.ansible.com/ansible/2.9/modules/synchronize\_module.html#synchronize-module](https://docs.ansible.com/ansible/2.9/modules/synchronize_module.html#synchronize-module)

- Rilindo

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 22, 2021, 8:14pm UTC](https://forum.ansible.com/t/keeping-directory-content-in-sync/36025/3 "2021-11-22T20:14:07Z")

</div>

Shameless plug: if your source directory contains templates, take a look at this role: [https://github.com/dnmvisser/ansible\_role\_template\_tree](https://github.com/dnmvisser/ansible_role_template_tree)
