# Problems using with\_fileglob

**URL:** <https://forum.ansible.com/t/problems-using-with-fileglob/13942>\
**Category:** Ansible Project\
**Created:** [November 20, 2013, 5:08pm UTC](https://forum.ansible.com/t/problems-using-with-fileglob/13942 "2013-11-20T17:08:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_Coombs](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Colin\_Coombs](https://forum.ansible.com/u/Colin_Coombs)\
**Post date:** [November 20, 2013, 5:08pm UTC](https://forum.ansible.com/t/problems-using-with-fileglob/13942/1 "2013-11-20T17:08:56Z")

</div>

I need to install configuration files for an application on multiple hosts, where

(1) each host needs a different collection of files, and  
(2) each file may have different content for each host.

I have the following file layout:

./roles/myapp/files/host01/foo.conf  
./roles/myapp/files/host02/foo.conf  
./roles/myapp/files/host02/bar.conf

etc etc.

In ./roles/myapp/tasks/main.yml, I want something like the following task:

- name: install config files  
copy: dest=/etc/myapp/{{ item }} src={{ ansible\_hostname }}/{{ item }}  
with\_fileglob:
- “{{ ansible\_hostname }}/\*.conf”

The problem is that the “with\_fileglob” line sets {{ item }} to an absolute filename like

/path/to/my/dir/roles/files/host01/foo.conf

which must be copied to /etc/myapp/foo.conf on the host01 system.

Is there some way I can extract just the ‘foo.conf’ part of the full name, or does ansible have  
a different way to perform such a task?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [November 20, 2013, 7:11pm UTC](https://forum.ansible.com/t/problems-using-with-fileglob/13942/2 "2013-11-20T19:11:24Z")

</div>

{{ path | basename }}

[http://ansibleworks.com/docs/playbooks\_variables.html#jinja2-filters](http://ansibleworks.com/docs/playbooks_variables.html#jinja2-filters)

---

<div class="post-metadata">

**Author:** ![Colin\_Coombs](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Colin\_Coombs](https://forum.ansible.com/u/Colin_Coombs)\
**Post date:** [November 20, 2013, 8:21pm UTC](https://forum.ansible.com/t/problems-using-with-fileglob/13942/3 "2013-11-20T20:21:46Z")

</div>

Ah, thank you! Somehow I managed to miss all mention of filters while scanning the docs earlier.

Just for completeness, I realised that in the particular case of the ‘copy’ module, I can just write

copy: dest=/etc/myapp src={{ item }}

and then I don’t actually need the basename in the first place.  
and the problem goes away
