# How do I nest lookup calls

**URL:** <https://forum.ansible.com/t/how-do-i-nest-lookup-calls/22573>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 16, 2016, 6:50pm UTC](https://forum.ansible.com/t/how-do-i-nest-lookup-calls/22573 "2016-09-16T18:50:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [September 16, 2016, 6:50pm UTC](https://forum.ansible.com/t/how-do-i-nest-lookup-calls/22573/1 "2016-09-16T18:50:29Z")

</div>

From [How to set environment variable with value obtained from ~/.aws/credentials?](https://groups.google.com/forum/#!topic/ansible-project/KCpkbncyOxI) I’m using lookup to get the values from a file off my home directory. But how do I nest the result of one lookup call into a subsequent lookup call? In the following code, I want to use the value of home\_dir in the subsequent lookups.

`

- name: Set AWS variables  
set\_fact:  
home\_dir: lookup(‘env’, ‘HOME’)  
aws\_access\_key\_id: “{{ lookup(‘ini’, ‘aws\_access\_key\_id section=default file=home\_dir/.aws/credentials’) }}”  
aws\_secret\_access\_key: “{{ lookup(‘ini’, ‘aws\_secret\_access\_key section=default file=home\_dir/.aws/credentials’) }}”  
`

The above code gives

`An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IOError: [Errno 2] No such file or directory: u'/home/myUser//andible_subdir/home_dir/.aws/credentials' fatal: [10.22.9.4]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}`

---

<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:** [September 16, 2016, 7:26pm UTC](https://forum.ansible.com/t/how-do-i-nest-lookup-calls/22573/2 "2016-09-16T19:26:41Z")

</div>

If you use file=~/.aws/credentials it will work.

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [September 16, 2016, 7:35pm UTC](https://forum.ansible.com/t/how-do-i-nest-lookup-calls/22573/3 "2016-09-16T19:35:56Z")

</div>

That was so obvious that i didn’t see it, thanks!!! Yes it worked. I was just wanting to use home\_dir somewhere else, but this gets me going.
