# Substitution inside lookup plugin

**URL:** <https://forum.ansible.com/t/substitution-inside-lookup-plugin/15122>\
**Category:** Ansible Project\
**Created:** [April 30, 2014, 2:45pm UTC](https://forum.ansible.com/t/substitution-inside-lookup-plugin/15122 "2014-04-30T14:45:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [April 30, 2014, 2:45pm UTC](https://forum.ansible.com/t/substitution-inside-lookup-plugin/15122/1 "2014-04-30T14:45:29Z")

</div>

I’d really like to do something like this:

- name: uploading ssh keys

action: authorized\_key user={{ item.username }}

key=“{{ lookup(‘file’, ‘keys/ssh.{{ item.username }}.pub’) }}”

with\_items: users

but the lookup plugin does not support substitution like that (I guess). Is there a simple workaround to include

the keys from files and still use the authorized\_key module? Otherwise, I’m going to have to just copy them over.

J

---

<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:** [April 30, 2014, 2:49pm UTC](https://forum.ansible.com/t/substitution-inside-lookup-plugin/15122/2 "2014-04-30T14:49:17Z")

</div>

"{{ lookup('file', 'keys/ssh.' + item.username + '.pub') }}"

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [April 30, 2014, 2:51pm UTC](https://forum.ansible.com/t/substitution-inside-lookup-plugin/15122/3 "2014-04-30T14:51:55Z")

</div>

Excerpts from Brian Coca's message of 2014-04-30 10:49:17 -0400:

> "{{ lookup('file', 'keys/ssh.' + item.username + '.pub') }}"

I'd add that, in the general case, you'll want to do:

&nbsp;&nbsp;&nbsp;&nbsp;{{ lookup('file', 'keys/ssh.' ~ item.username ~'.pub') }}

Using the tilde concatenation operator casts values to strings before  
concatenation.

---

<div class="post-metadata">

**Author:** ![Jason\_Levitt](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@Jason\_Levitt](https://forum.ansible.com/u/Jason_Levitt)\
**Post date:** [April 30, 2014, 3:47pm UTC](https://forum.ansible.com/t/substitution-inside-lookup-plugin/15122/4 "2014-04-30T15:47:32Z")

</div>

Looks good. Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 30, 2014, 8:19pm UTC](https://forum.ansible.com/t/substitution-inside-lookup-plugin/15122/5 "2014-04-30T20:19:15Z")

</div>

Though username would likely be a string anyway 🙂
