# Globbing with Lookup

**URL:** <https://forum.ansible.com/t/globbing-with-lookup/16483>\
**Category:** Ansible Project\
**Created:** [October 10, 2014, 7:50am UTC](https://forum.ansible.com/t/globbing-with-lookup/16483 "2014-10-10T07:50:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navid\_Paya](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Navid\_Paya](https://forum.ansible.com/u/Navid_Paya)\
**Post date:** [October 10, 2014, 7:50am UTC](https://forum.ansible.com/t/globbing-with-lookup/16483/1 "2014-10-10T07:50:11Z")

</div>

Hi all  
Not sure if this is even the right tile. So I have a set of SSH keys, I want to be used as authorized keys for users. I’ve put all of them in a directory and am trying to do the job but nothing happens. So I did some debugging. This is what I do when not using a variable:

- name: Some debugging  
debug: msg=“{{ lookup(‘file’, ‘public\_ssh\_keys/navid.pub’) }}”

And it returns what I expect. Now I try doing a loop:

- name: Some debugging  
debug: msg=“{{ lookup(‘file’, ‘public\_ssh\_keys/{{ item }}.pub’) }}”  
with\_items:
- navid

But this time it returns this:

TASK: [base-ami | Some debugging] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [default] =\> (item=navid) =\> {  
“item”: “navid”,  
“msg”: “”  
}

So how am I supposed to have it return what I expect? I think it’s probably a matter of using the single and double quotes right but how?

Regards

Navid

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 10, 2014, 12:38pm UTC](https://forum.ansible.com/t/globbing-with-lookup/16483/2 "2014-10-10T12:38:16Z")

</div>

mustaches don't stack!

you want:  
"{{ lookup('file', 'public\_ssh\_keys/' + item + '.pub') }}"

---

<div class="post-metadata">

**Author:** ![Navid\_Paya](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Navid\_Paya](https://forum.ansible.com/u/Navid_Paya)\
**Post date:** [October 13, 2014, 2:20am UTC](https://forum.ansible.com/t/globbing-with-lookup/16483/3 "2014-10-13T02:20:33Z")

</div>

Stupid me. Thanks, Brian. That worked like a charm.

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [October 13, 2014, 9:09pm UTC](https://forum.ansible.com/t/globbing-with-lookup/16483/4 "2014-10-13T21:09:23Z")

</div>

Hi Navid,

I 'm trying something similar, based on: [http://blather.michaelwlucas.com/archives/1819](http://blather.michaelwlucas.com/archives/1819)

Do you mind share your approach?

Thanks,  
Wawrzek

---

<div class="post-metadata">

**Author:** ![Navid\_Paya](https://avatars.discourse-cdn.com/v4/letter/n/9fc29f/32.png) [@Navid\_Paya](https://forum.ansible.com/u/Navid_Paya)\
**Post date:** [October 14, 2014, 8:12am UTC](https://forum.ansible.com/t/globbing-with-lookup/16483/5 "2014-10-14T08:12:27Z")

</div>

Here’s how I did it. Created a directory with the public keys in it. For instance:

base-ami/files/public\_ssh\_keys/jack.pub  
base-ami/files/public\_ssh\_keys/jill.pub

- name: Create basic users  
user: name={{ item }} shell=/bin/bash groups=grabtaxi  
with\_items:
- jack
- jill

And then used lookup to populate the keys:

- name: Use the public keys from the users for the their login  
authorized\_key: user={{ item }} key=“{{ lookup(‘file’, ‘public\_ssh\_keys/’ + item + ‘.pub’) }}”  
with\_items:
- jack
- jill

You could make it fancier using vars and all but I think you get the gist of it.
