Substitution inside lookup plugin

54 views
Skip to first unread message

Slim Slam

unread,
Apr 30, 2014, 10:45:29 AM4/30/14
to ansible...@googlegroups.com
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

Brian Coca

unread,
Apr 30, 2014, 10:49:17 AM4/30/14
to ansible...@googlegroups.com
"{{ lookup('file', 'keys/ssh.' + item.username + '.pub') }}"



--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno

C. Morgan Hamill

unread,
Apr 30, 2014, 10:51:55 AM4/30/14
to ansible-project
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.
--
Morgan

Slim Slam

unread,
Apr 30, 2014, 11:47:32 AM4/30/14
to ansible...@googlegroups.com
Looks good. Thanks!

Michael DeHaan

unread,
Apr 30, 2014, 4:19:15 PM4/30/14
to ansible...@googlegroups.com
Though username would likely be a string anyway :)





--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1398869426-sup-8110%40al.wesleyan.edu.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages