# files precedence

**URL:** <https://forum.ansible.com/t/files-precedence/13931>\
**Category:** Ansible Project\
**Created:** [November 18, 2013, 7:03pm UTC](https://forum.ansible.com/t/files-precedence/13931 "2013-11-18T19:03:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mayeu](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@Mayeu](https://forum.ansible.com/u/Mayeu)\
**Post date:** [November 18, 2013, 7:03pm UTC](https://forum.ansible.com/t/files-precedence/13931/1 "2013-11-18T19:03:59Z")

</div>

Hi,

Following the principle of variable precedence, I am wondering why  
there is no such concept for files.

Example:

I have the following playbooks:

- -- ansible-playbook-some\_app ------  
- - ansible-playbook-some\_app  
&nbsp;&nbsp;- files  
&nbsp;&nbsp;&nbsp;&nbsp;- some\_files  
&nbsp;&nbsp;&nbsp;&nbsp;- private\_ssl\_files \<- not in the git repo, used for tests only  
&nbsp;&nbsp;- tasks  
&nbsp;&nbsp;&nbsp;&nbsp;- main.yml  
&nbsp;&nbsp;- test.yml \<- playbook used for test  
&nbsp;&nbsp;- Vagrantfile \<- VM used for test  
&nbsp;&nbsp;- .git  
- -----------------------------------

^ this playbook is intended to be the most generic possible, I do not  
want any host specific data in the folder layout, since it will be used  
for a lot of different host.

- -- ansible-playbook-host ----------  
- - ansible-playbook-host\_1  
&nbsp;&nbsp;- files  
&nbsp;&nbsp;&nbsp;&nbsp;- private\_ssl\_files \<- the ssl files for the host  
&nbsp;&nbsp;-roles  
&nbsp;&nbsp;&nbsp;&nbsp;- some\_app \<- git submodule of the previous playbook  
&nbsp;&nbsp;&nbsp;&nbsp;- other\_app\_1 \<- git submodule  
&nbsp;&nbsp;&nbsp;&nbsp;- ...  
&nbsp;&nbsp;- the\_rest\_of\_the\_playbook\_layout  
- ------------------------------------

I only want submodules in my roles folder to avoid a mess and loosing  
track of what is modified on my host. What I would like, is to be able  
to put my ssl files for the host in the root files folder, and not in  
the roles/some\_app/files folder. It seems that by default ansible does  
not allow this. Unlike the vars, there is no files precedence.

Is there a clean way to handle this?

I see a different use case of files (even templates) precedence, is it  
a planned feature? Does it has been discussed earlier?

I am new to ansible, so it may be possible that I do not see the  
ansible-way of doing it. Do not hesitate to point me to the revelant  
discussion/doc/example-playbook 🙂

Regards

- --  
Mayeu  
[http://6x9.fr](http://6x9.fr)

---

<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 18, 2013, 7:23pm UTC](https://forum.ansible.com/t/files-precedence/13931/2 "2013-11-18T19:23:51Z")

</div>

> I only want submodules in my roles folder to avoid a mess and loosing  
> track of what is modified on my host. What I would like, is to be able  
> to put my ssl files for the host in the root files folder, and not in  
> the roles/some\_app/files folder. It seems that by default ansible does  
> not allow this. Unlike the vars, there is no files precedence.

src=../../{{ inventory\_hostname }}/file.txt ?

> Is there a clean way to handle this?
> 
> I see a different use case of files (even templates) precedence, is it  
> a planned feature? Does it has been discussed earlier?

Consider looking into "with\_first\_found" if you want to look into multiple  
locations and have a default.

---

<div class="post-metadata">

**Author:** ![Mayeu](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@Mayeu](https://forum.ansible.com/u/Mayeu)\
**Post date:** [November 19, 2013, 5:54pm UTC](https://forum.ansible.com/t/files-precedence/13931/3 "2013-11-19T17:54:47Z")

</div>

Thank you for your response.

> src=../../{{ inventory\_hostname }}/file.txt ?
> 
> Consider looking into "with\_first\_found" if you want to look into  
> multiple locations and have a default.

Both those solutions assumes that I know what is the path to the file,  
wich may not be true. If the playbook may be a role of one playbook, or  
a role of a role, wich then make it not always possible to know the  
inclusion level.

By accident I discover something that allow me to do file precedence.  
Basically, instead of putting src=\<file\_name\> I used  
src=files/\<file\_name\>. By default Ansible use only `./files/\<file_name\>`  
of the playbook, by adding `files/`, Ansible get the first \<file\_name\>  
found in a `files` folder, thus using precedence.

I made a little repository to illustrate this:  
[https://github.com/Mayeu/ansible-playbook-file\_precedence\_test](https://github.com/Mayeu/ansible-playbook-file_precedence_test)

So, is it a bug, or a feature? If it is a bug, it should be promoted to  
a feature, it is really handy to have file precedence when you try to  
have generic playbook. If it is already a feature, I missed the part in  
the doc specifying that 🙂

- --  
Mayeu  
[http://6x9.fr](http://6x9.fr)

---

<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, 3:42am UTC](https://forum.ansible.com/t/files-precedence/13931/4 "2013-11-20T03:42:39Z")

</div>

Ansible looks in the files directory of the role first by design, yes.
