# locations for the "lookup('file'...)

**URL:** <https://forum.ansible.com/t/locations-for-the-lookup-file/15748>\
**Category:** Ansible Project\
**Created:** [July 23, 2014, 8:48pm UTC](https://forum.ansible.com/t/locations-for-the-lookup-file/15748 "2014-07-23T20:48:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [July 23, 2014, 8:48pm UTC](https://forum.ansible.com/t/locations-for-the-lookup-file/15748/1 "2014-07-23T20:48:18Z")

</div>

Hi,

I’m trying to get through my “slow” day here - can’t figure out (or locate documetation explaining it) - where does “lookup(‘file’,…)” looks indeed.

I have a structure:

group\_vars/all.yml  
pgsql\_key  
pgsql\_key.pub  
roles/pgsql/tasks/main.yml  
site.yml

under all.yml I have var defined:  
…  
pgsql\_ssh\_key=“pgsql\_key”  
…

inside of roles/pgsql/tasks/main.yml I have:

…  
debug: var=pgsql\_ssh\_key  
debug: msg={{ lookup(‘file’,pgsql\_ssh\_key) }}  
…

site.yml is simple:

- hosts: pgsql  
roles:
- pgsql

however I get empty contents of lookup call while debug for the pgsql\_ssh\_key returns proper value. Seems like lookup wants to pick up my pgsql\_ssh\_key under roles/pgsql/files, but I’d like to keep it top-level (other roles will be using it). What did I miss?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 23, 2014, 10:12pm UTC](https://forum.ansible.com/t/locations-for-the-lookup-file/15748/2 "2014-07-23T22:12:08Z")

</div>

It looks relative to the playbook root, and if in roles, will look in the “files/” dir of roles.

If you try it and it can’t find something, it will tell you where it looked.

---

<div class="post-metadata">

**Author:** ![Dimon](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@Dimon](https://forum.ansible.com/u/Dimon)\
**Post date:** [July 23, 2014, 11:41pm UTC](https://forum.ansible.com/t/locations-for-the-lookup-file/15748/3 "2014-07-23T23:41:02Z")

</div>

> It looks relative to the playbook root, and if in roles, will look in the “files/” dir of roles.

I’ve noticed that it does look in role’s “files” dir but apparently it doesn’t look at playbook root. Is there a parameter I tweaked someplace?

> If you try it and it can’t find something, it will tell you where it looked.

tells me it can’t find it in roles/pgsql/files

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 24, 2014, 11:12am UTC](https://forum.ansible.com/t/locations-for-the-lookup-file/15748/4 "2014-07-24T11:12:08Z")

</div>

It won’t look in the playbook root when inside a role, no. Sorry I mispoke on that one.

You can path the src as {{ lookup(‘file’, playbook\_dir + ‘/filename’) }} if you want this, and it will find things there using the (derived) path of the playbook root.

Ansible will look in the root if you are not using roles.

Relative pathing would also find it.
