# Synchronize module and with\_first\_found

**URL:** <https://forum.ansible.com/t/synchronize-module-and-with-first-found/15334>\
**Category:** Ansible Project\
**Created:** [May 26, 2014, 9:00pm UTC](https://forum.ansible.com/t/synchronize-module-and-with-first-found/15334 "2014-05-26T21:00:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carlos\_A\_Carnero\_Del](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@Carlos\_A\_Carnero\_Del](https://forum.ansible.com/u/Carlos_A_Carnero_Del)\
**Post date:** [May 26, 2014, 9:00pm UTC](https://forum.ansible.com/t/synchronize-module-and-with-first-found/15334/1 "2014-05-26T21:00:33Z")

</div>

Hi,

I (an Ansible newb) need to pass a directory of configuration files to  
remote nodes, so that the files on the remote end should \*exactly\*  
mirror what I have on the Ansible side. For instance, in my files  
directory (using a role) I have the following directories

&nbsp;&nbsp;&nbsp;&nbsp;etc/yum.repos.d-a.host.fqdn.example.com  
&nbsp;&nbsp;&nbsp;&nbsp;etc/yum.repos.d-b.host.fqdn.example.com  
&nbsp;&nbsp;&nbsp;&nbsp;etc/yum.repos.d-DEFAULT

with CentOS repository definitions inside. Each machine's repository  
sources could be customized by making a new directory there with its  
FQDN attached to the file name. I'm using the sychronize module in a  
task like

&nbsp;&nbsp;&nbsp;&nbsp;- name: Repository configuration  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;synchronize: dest=/etc/yum.repos.d  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;src="{{ item }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recursive=yes delete=yes owner=no group=no  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_first\_found:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "etc/yum.repos.d-{{ ansible\_fqdn }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "etc/yum.repos.d-DEFAULT"

This works incorrectly, since it will put the containing directory,  
what has been properly found with with\_first\_found inside the  
destination. This is a classic rsync "issue" easily solved by adding a  
"/" at the end. I have tried several combinations an the only one that  
I got working is by using src="{{ item }}/" instead of src="{{ item  
}}".

I'm wondering if this is the intented behavior? Not world breaking at  
all, but it made me wonder; and, of course, I could ways resort to  
pure rsync.

Alternatively, what's the best way to synchronize directories based on  
file name "templating"? The copy module works as expected but it is  
one way as it will never delete on the remote what is not in the  
source.

Best regards,  
Carlos.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 27, 2014, 8:00pm UTC](https://forum.ansible.com/t/synchronize-module-and-with-first-found/15334/2 "2014-05-27T20:00:41Z")

</div>

“This works incorrectly, since it will put the containing directory,  
what has been properly found with with\_first\_found inside the  
destination.”

Seems like you’d want the trailing slash here, since synchronize is in fact just a thin wrapper around

local\_action: rsync …

---

<div class="post-metadata">

**Author:** ![Carlos\_A\_Carnero\_Del](https://avatars.discourse-cdn.com/v4/letter/c/7ea924/32.png) [@Carlos\_A\_Carnero\_Del](https://forum.ansible.com/u/Carlos_A_Carnero_Del)\
**Post date:** [May 28, 2014, 12:35pm UTC](https://forum.ansible.com/t/synchronize-module-and-with-first-found/15334/3 "2014-05-28T12:35:52Z")

</div>

> Seems like you'd want the trailing slash here, since synchronize  
> is in fact just a thin wrapper around
> 
> local\_action: rsync ...

I knew that the synchronize module was a wrapper over rsync. What's  
new to me is that it is a local\_action. I even seem to remember  
synchronize failing when the remote system did not have rsync  
installed. In any case, I'm experimenting exactly with that: a custom  
local\_action with rsync.

Thanks a lot,  
Carlos.
