# trouble use file lookup as variable

**URL:** <https://forum.ansible.com/t/trouble-use-file-lookup-as-variable/21102>\
**Category:** Ansible Project\
**Created:** [April 8, 2016, 8:43am UTC](https://forum.ansible.com/t/trouble-use-file-lookup-as-variable/21102 "2016-04-08T08:43:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Louis1](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@Louis1](https://forum.ansible.com/u/Louis1)\
**Post date:** [April 8, 2016, 8:43am UTC](https://forum.ansible.com/t/trouble-use-file-lookup-as-variable/21102/1 "2016-04-08T08:43:40Z")

</div>

I am having trouble using the file lookup plugin with a playbook that use two roles:  
roles:

- { role: role\_1 }
- { role: role\_Z }

“role\_1” sets a variable using the lookup plugin in: role\_1/vars/main.yml:

file\_contents: “{{ lookup(‘file’, ‘config’) }}”

I am able to correctly list the contents from: role\_1/tasks/main.yml:

- debug: msg=“the contents of config is: {{ file\_contents }}”

when i try to use the variable from role\_Z/tasks/main.yml, ansible throws an error:

- debug: msg=“the contents of config is: {{ file\_contents }}”

FAILED! =\> {“failed”: true, “msg”: “the file\_name ‘/path/to/basedir/config’ does not exist, or is not readable”}

I was expecting that “{{ file\_contents }}” would have the actual contents of the file as a string, but it seems that it is actually a closure (future?) instead, and when it is used in “role\_Z”, the closure is called and the path is now incorrect because the file does not exist in “role\_Z”.

Is there a way to force the execution of “lookup()” so that I can get the actual file contents as a string rather than a closure?
