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
(Brian Coca)
December 9, 2014, 4:03pm
2
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/*
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
(Brian Coca)
December 9, 2014, 5:25pm
4
Weird, it works for me in both formats.
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/*
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” )}}’
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/*