Synchronize module and with_first_found

69 views
Skip to first unread message

Carlos A. Carnero Delgado

unread,
May 27, 2014, 10:36:46 AM5/27/14
to ansible...@googlegroups.com
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

etc/yum.repos.d-a.host.fqdn.example.com
etc/yum.repos.d-b.host.fqdn.example.com
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

- name: Repository configuration
synchronize: dest=/etc/yum.repos.d
src="{{ item }}"
recursive=yes delete=yes owner=no group=no
with_first_found:
- "etc/yum.repos.d-{{ ansible_fqdn }}"
- "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.

Michael DeHaan

unread,
May 27, 2014, 4:00:46 PM5/27/14
to ansible...@googlegroups.com
"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 ...




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAPjvz2mAkCm7Xc89e_k0uD5F2gm2EEF54KkJCmFr3VwsP6y6Tw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Carlos A. Carnero Delgado

unread,
May 28, 2014, 8:35:56 AM5/28/14
to ansible...@googlegroups.com
> 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.
Reply all
Reply to author
Forward
0 new messages