# Way for a role to refer to files relative to the role?

**URL:** <https://forum.ansible.com/t/way-for-a-role-to-refer-to-files-relative-to-the-role/16284>\
**Category:** Ansible Project\
**Created:** [September 19, 2014, 3:48am UTC](https://forum.ansible.com/t/way-for-a-role-to-refer-to-files-relative-to-the-role/16284 "2014-09-19T03:48:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Abramowitz](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marc\_Abramowitz](https://forum.ansible.com/u/Marc_Abramowitz)\
**Post date:** [September 19, 2014, 3:48am UTC](https://forum.ansible.com/t/way-for-a-role-to-refer-to-files-relative-to-the-role/16284/1 "2014-09-19T03:48:32Z")

</div>

So roles have a “files” directory and for some actions and attributes they are evaluated relative to this directory (e.g.: the “src” attribute of the “copy” module). So with:

# roles/common/tasks/main.yml

- name: Copy in ssh key files  
copy:  
src=“devops.pem”  
dest=“/home/{{ ansible\_user\_id }}/.ssh/id\_rsa”  
mode=600  
tags:
- ssh\_key

src=“devops.pem” will find my file in roles/common/files/devops.pem

For other actions, this doesn’t work – for example:

- name: Make sure that devops.pem is not group/world readable  
local\_action: file path=devops.pem mode=600  
tags:
- ssh\_key
- ssh\_key\_local

In this case, it will not find the file in roles/common/files/devops.pem – it seems to look for the file relative to the playbook?

How can I reference a file relative to the role I’m referencing it in? – e.g.: something like:

- name: Make sure that devops.pem is not group/world readable  
local\_action: file path={{ current\_role\_dir }}/files/devops.pem mode=600  
tags:
- ssh\_key
- ssh\_key\_local

---

<div class="post-metadata">

**Author:** ![Marc\_Abramowitz](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marc\_Abramowitz](https://forum.ansible.com/u/Marc_Abramowitz)\
**Post date:** [September 19, 2014, 3:52am UTC](https://forum.ansible.com/t/way-for-a-role-to-refer-to-files-relative-to-the-role/16284/2 "2014-09-19T03:52:27Z")

</div>

local\_action: file path={{ inventory\_dir }}/…/roles/common/files/devops.pem mode=600

works, but hopefully there’s a cleaner way that doesn’t have to include “…/roles/common” in it…?
