File lookup issue in 1.8.2

130 views
Skip to first unread message

Mathieu Guillaume

unread,
Dec 9, 2014, 10:47:30 AM12/9/14
to ansible...@googlegroups.com
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

Brian Coca

unread,
Dec 9, 2014, 11:04:00 AM12/9/14
to ansible...@googlegroups.com
I did very simple (if contrived) test and this seems to work fine:


- copy: content={{lookup('file',item)}} dest=/tmp/{{item|basename}}
with_fileglob:
- files/*


--
Brian Coca

Mathieu Guillaume

unread,
Dec 9, 2014, 11:32:23 AM12/9/14
to ansible...@googlegroups.com
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


Brian Coca

unread,
Dec 9, 2014, 12:25:14 PM12/9/14
to ansible...@googlegroups.com
Weird, it works for me in both formats.

--
Brian Coca

Solomon Gifford

unread,
Jan 6, 2015, 1:51:26 PM1/6/15
to ansible...@googlegroups.com
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/*

Solomon Gifford

unread,
Jan 6, 2015, 2:08:29 PM1/6/15
to ansible...@googlegroups.com
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" )}}'

On Tuesday, December 9, 2014 11:32:23 AM UTC-5, Mathieu Guillaume wrote:

Solomon Gifford

unread,
Jan 22, 2015, 1:57:19 PM1/22/15
to ansible...@googlegroups.com
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/*
Reply all
Reply to author
Forward
0 new messages