Substitution inside lookup plugin

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

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

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:

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

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

Looks good. Thanks!

Though username would likely be a string anyway :slight_smile: