# File lookup issue in 1.8.2

**URL:** <https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998>\
**Category:** Ansible Project\
**Created:** [December 9, 2014, 3:47pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998 "2014-12-09T15:47:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu\_Guillaume](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Mathieu\_Guillaume](https://forum.ansible.com/u/Mathieu_Guillaume)\
**Post date:** [December 9, 2014, 3:47pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998/1 "2014-12-09T15:47:30Z")

</div>

I’m using a task similar to this to add keys to a remote user:

- authorized\_key: user=bob key=‘{{lookup(“file”, item)}}’  
with\_fileglob:
- /some/absolute/path/id\_\*.pub

This worked fine up to (and including) 1.8.1

In 1.8.2, I’m getting: ERROR: Unexpected error in during lookup: ‘item’ is undefined

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 9, 2014, 4:03pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998/2 "2014-12-09T16:03:56Z")

</div>

I did very simple (if contrived) test and this seems to work fine:

&nbsp;&nbsp;&nbsp;- copy: content={{lookup('file',item)}} dest=/tmp/{{item|basename}}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_fileglob:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- files/\*

---

<div class="post-metadata">

**Author:** ![Mathieu\_Guillaume](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Mathieu\_Guillaume](https://forum.ansible.com/u/Mathieu_Guillaume)\
**Post date:** [December 9, 2014, 4:32pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998/3 "2014-12-09T16:32:23Z")

</div>

Looks like some kind of parsing issue, if I use the full YAML syntax below it works, but not if I use key=…

Working:

- authorized\_key:  
user: bob  
key: “{{lookup(‘file’,item)}}”  
with\_fileglob:
- /some/absolute/path/id\_\*.pub

Not working:

- authorized\_key: user=bob key=‘{{lookup(“file”, item)}}’  
with\_fileglob:
- /some/absolute/path/id\_\*.pub

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 9, 2014, 5:25pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998/4 "2014-12-09T17:25:11Z")

</div>

Weird, it works for me in both formats.

---

<div class="post-metadata">

**Author:** ![Solomon\_Gifford](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@Solomon\_Gifford](https://forum.ansible.com/u/Solomon_Gifford)\
**Post date:** [January 6, 2015, 6:51pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998/5 "2015-01-06T18:51:26Z")

</div>

Neither are working for me - I’m getting the same issue even when in yaml format. If I use item.0 the error disappears (but of course the task fails because it is incorrect).

- authorized\_key:  
user: someuser  
key: “{{lookup(‘file’,item)}}”  
with\_fileglob:
- /tmp/keys/\*

---

<div class="post-metadata">

**Author:** ![Solomon\_Gifford](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@Solomon\_Gifford](https://forum.ansible.com/u/Solomon_Gifford)\
**Post date:** [January 6, 2015, 7:08pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998/6 "2015-01-06T19:08:29Z")

</div>

Matthieu,

I was able to use the pipe lookup to get around this:

- authorized\_key: user=bob key=‘{{lookup(“pipe”, “cat /some/absolute/path/id\_\*.pub” )}}’

---

<div class="post-metadata">

**Author:** ![Solomon\_Gifford](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@Solomon\_Gifford](https://forum.ansible.com/u/Solomon_Gifford)\
**Post date:** [January 22, 2015, 6:57pm UTC](https://forum.ansible.com/t/file-lookup-issue-in-1-8-2/16998/7 "2015-01-22T18:57:19Z")

</div>

Aha - one more piece.

It works fine as a task but not as a post\_task in a playbook.

This playbook fails:

- hosts: servers  
post\_tasks:
- name: Set the authorized key everywhere  
authorized\_key: user=someuser key=“{{lookup(‘file’, item)}}”  
with\_fileglob:
- /tmp/keys/\*

This one succeeds:

- hosts: servers  
tasks:
- name: Set the authorized key everywhere  
authorized\_key: user=someuser key=“{{lookup(‘file’, item)}}”  
with\_fileglob:
- /tmp/keys/\*
