# Using lookup plugin within include\_vars to build file name

**URL:** <https://forum.ansible.com/t/using-lookup-plugin-within-include-vars-to-build-file-name/23391>\
**Category:** Ansible Project\
**Created:** [January 5, 2017, 8:43pm UTC](https://forum.ansible.com/t/using-lookup-plugin-within-include-vars-to-build-file-name/23391 "2017-01-05T20:43:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [January 5, 2017, 8:43pm UTC](https://forum.ansible.com/t/using-lookup-plugin-within-include-vars-to-build-file-name/23391/1 "2017-01-05T20:43:58Z")

</div>

Running Ansible 2.1.1

I want to dynamically build the variable name for a file I wish to load using “include\_vars.” it doesn’t work using the lookup plugin but the lookup plugin itself does work when I use the “debug” method.

- name: load var file  
include\_vars: “{{ lookup(‘ini’,‘environment section=environment\_info file=/etc/abc123.conf’) }}.yml”

Error:

`

TASK [sam : load var file] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/ssen/ansible\_ops/roles/sam/tasks/main.yml:5  
An exception occurred during task execution. The full traceback is:  
Traceback (most recent call last):  
File “/usr/lib/python2.7/site-packages/ansible/executor/task\_executor.py”, line 124, in run  
res = self.\_execute()  
File “/usr/lib/python2.7/site-packages/ansible/executor/task\_executor.py”, line 448, in \_execute  
result = self.\_handler.run(task\_vars=variables)  
File “/usr/lib/python2.7/site-packages/ansible/plugins/action/include\_vars.py”, line 39, in run  
source = self.\_loader.path\_dwim\_relative(self.\_task.\_role.\_role\_path, ‘vars’, source)  
File “/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py”, line 236, in path\_dwim\_relative  
if source.startswith(‘~’) or source.startswith(‘/’):  
AttributeError: ‘NoneType’ object has no attribute ‘startswith’

fatal: [localhost]: FAILED! =\> {“failed”: true, “msg”: “Unexpected failure during module execution.”, “stdout”: “”}  
`

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 6, 2017, 8:47pm UTC](https://forum.ansible.com/t/using-lookup-plugin-within-include-vars-to-build-file-name/23391/2 "2017-01-06T20:47:18Z")

</div>

Can you workaround it by setting a variable to the result of your  
lookup and then use this variable for the file name?

Johannes

---

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [January 7, 2017, 6:27pm UTC](https://forum.ansible.com/t/using-lookup-plugin-within-include-vars-to-build-file-name/23391/3 "2017-01-07T18:27:32Z")

</div>

Yes that’s what I ended up doing. I’m not sure why I’m not able to use the lookup plugin within the line.
