# Where to put files and templates that don't belong to a role

**URL:** <https://forum.ansible.com/t/where-to-put-files-and-templates-that-dont-belong-to-a-role/27247>\
**Category:** Ansible Project\
**Created:** [April 11, 2018, 1:13pm UTC](https://forum.ansible.com/t/where-to-put-files-and-templates-that-dont-belong-to-a-role/27247 "2018-04-11T13:13:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clayton\_Louden](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Clayton\_Louden](https://forum.ansible.com/u/Clayton_Louden)\
**Post date:** [April 11, 2018, 1:13pm UTC](https://forum.ansible.com/t/where-to-put-files-and-templates-that-dont-belong-to-a-role/27247/1 "2018-04-11T13:13:51Z")

</div>

Hi everyone,

Where do you usually put files or templates that are just used in a certain play but are not part of a role? Currently I do have them just alongside my playbooks organised by play

`someplay.yml files/ someplay/somefile someotherplay/someotherfile templates someplay/sometemplate.j2 someotherplay/someothertemplate.j2`

This however is a bit awkward when using it in a play since I always have to specify the play subfolder in files/ or templates/

`

- name: Copy extensions.conf  
copy: src=files/someplay/extensions.conf dest=/etc/extensions.conf

`

Now this can be easily solved by converting that particular playbook into a role and then just using ‘templates/somethemplate.js’ and ‘files/somefile’ without the ‘play’ subdirectory. That however has the side-effect that I’d have a rather stupid playbook that just includes a role, which I find rather annoying:

`

- name: Configure server  
hosts: mysinglehost  
roles:
- role: custom\_configure\_server\_role  
`

I’ve heard from other ansible guys that they treat ‘everything as a role’. Maybe it’s just me but I find that opening a playbook just to find out that it contains just one custom role a bit redundant. How do you guys usually do this?

Cheers!

---

<div class="post-metadata">

**Author:** ![Mike\_Garris](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Mike\_Garris](https://forum.ansible.com/u/Mike_Garris)\
**Post date:** [April 11, 2018, 1:25pm UTC](https://forum.ansible.com/t/where-to-put-files-and-templates-that-dont-belong-to-a-role/27247/2 "2018-04-11T13:25:36Z")

</div>

I am in the boat of treating everything as a role.

> \_\_\_\_some\_app
> 
> > \_\_\_\_site.yml  
> > \_\_\_\_roles
> > 
> > > \_\_\_\_some\_app\_name
> > > 
> > > > \_\_\_\_vars  
> > > > \_\_\_\_tasks  
> > > > \_\_\_\_defaults  
> > > > \_\_\_\_files  
> > > > \_\_\_\_templates

Now you could, if needed, create a site.yml that would have variables to execute, or not execute, certain roles inside of the “roles” directory.

site.yml

tasks:

- include\_role:  
name: some\_app\_1  
when: some\_app1\_variable == “true”

- include\_role:  
name: some\_app\_2  
when: some\_app2\_variable == “true”

This doesn’t really get around your problem of having a generic location for files/templates. Just an opinion on the “everything as a role” comment.

Happy Coding!!

---

<div class="post-metadata">

**Author:** ![Clayton\_Louden](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Clayton\_Louden](https://forum.ansible.com/u/Clayton_Louden)\
**Post date:** [April 11, 2018, 1:30pm UTC](https://forum.ansible.com/t/where-to-put-files-and-templates-that-dont-belong-to-a-role/27247/3 "2018-04-11T13:30:48Z")

</div>

Hi Mike,

> I am in the boat of treating everything as a role.

[...]

> Just an opinion on the "everything as a role" comment.

An extra opinion is very welcome. If I'm the only person who doesn't treat "everything as a role" then maybe it's time to think about changing my ways 😉

Cheers!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 11, 2018, 5:47pm UTC](https://forum.ansible.com/t/where-to-put-files-and-templates-that-dont-belong-to-a-role/27247/4 "2018-04-11T17:47:52Z")

</div>

> Hi everyone,
> 
> Where do you usually put files or templates that are just used in a certain  
> play but are not part of a role?

For the most part in a role.

> Currently I do have them just alongside my  
> playbooks organised by play

Some file like ssh and gpg public keys is located on top level inside files/ directly.  
The reason for this is that it make it easier for people since they don't need to go deep down into a role if they need to change their files or add files.

> This however is a bit awkward when using it in a play since I always have  
> to specify the play subfolder in files/ or templates/
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- name: Copy extensions.conf  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;copy: src=files/someplay/extensions.conf dest=/etc/extensions.conf
> 
> Now this can be easily solved by converting that particular playbook into a  
> role and then just using 'templates/somethemplate.js' and 'files/somefile'  
> without the 'play' subdirectory.

When using template it automatically check the templates folder so you don't need to include templates/, somethemplate.js suffice.  
The same are try for copy and the files/ directory in a role.

> That however has the side-effect that I'd  
> have a rather stupid playbook that just includes a role, which I find  
> rather annoying:
> 
> - name: Configure server  
> &nbsp;&nbsp;hosts: mysinglehost  
> &nbsp;&nbsp;roles:  
> &nbsp;&nbsp;&nbsp;&nbsp;- role: custom\_configure\_server\_role

Personally i find this cleaner that having a task.  
And if you have more than one host that need it, you only have one place to change the code if needed.

You can leave out role:

&nbsp;&nbsp;roles:  
&nbsp;&nbsp;&nbsp;&nbsp;- custom\_configure\_server\_role

> I've heard from other ansible guys that they treat 'everything as a role'.  
> Maybe it's just me but I find that opening a playbook just to find out that  
> it contains just one custom role a bit redundant. How do you guys usually  
> do this?

If the config is very small I sometimes do someting like this since it fast and easy to grasp

&nbsp;&nbsp;- name: Runing check every minute  
&nbsp;&nbsp;&nbsp;&nbsp;copy:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content: |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Managed by Ansible  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\* \* \* \* \* root /usr/local/bin/check  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest: /etc/cron.d/hourly\_check
