Globbing with Lookup

45 views
Skip to first unread message

Navid Paya

unread,
Oct 10, 2014, 3:50:11 AM10/10/14
to ansible...@googlegroups.com
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

Brian Coca

unread,
Oct 10, 2014, 8:38:19 AM10/10/14
to ansible...@googlegroups.com
mustaches don't stack!

you want:
"{{ lookup('file', 'public_ssh_keys/' + item + '.pub') }}"
> --
> 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/733e3c63-80c1-4fba-bf72-e1ebca70e45b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



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

Navid Paya

unread,
Oct 12, 2014, 10:20:33 PM10/12/14
to ansible...@googlegroups.com
Stupid me. Thanks, Brian. That worked like a charm.

Wawrzek Niewodniczanski

unread,
Oct 13, 2014, 5:09:23 PM10/13/14
to ansible...@googlegroups.com


On Friday, 10 October 2014 08:50:11 UTC+1, Navid Paya wrote:
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.

Hi Navid,

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

Do you mind share your approach?

Thanks,
Wawrzek

Navid Paya

unread,
Oct 14, 2014, 4:12:31 AM10/14/14
to ansible...@googlegroups.com
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.

 


  

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/E6--MjSuBJ8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages