# ssh-keys

**URL:** <https://forum.ansible.com/t/ssh-keys/16404>\
**Category:** Ansible Project\
**Created:** [October 2, 2014, 1:52pm UTC](https://forum.ansible.com/t/ssh-keys/16404 "2014-10-02T13:52:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [October 2, 2014, 1:52pm UTC](https://forum.ansible.com/t/ssh-keys/16404/1 "2014-10-02T13:52:04Z")

</div>

Hi,

In my setup, I have a master host that contains all accounts, these accounts are to be kept in sync across a bunch of isolated remote environments.  
The account creation/deletion is not a problem, however I can’t seem to find out a way to deploy the ssh key for each user without having to write a separate statement for each account.

What I’d like to do is:

authorized\_key: user={{ item }} key={{ lookup(‘file’, public-keys/{{ item.1 }}.pub) }}  
with\_items:  
-list\_of\_my\_users\_obtained\_earlier

Sadly this doesn’t work (can’t figure out why it doesn’t either, no error is given).  
Is there another way of doing this?

Thanks,  
Nico

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 2, 2014, 1:57pm UTC](https://forum.ansible.com/t/ssh-keys/16404/2 "2014-10-02T13:57:17Z")

</div>

I am not sure what list\_of\_my\_users\_obtained\_earlier looks like, but assuming it is just a normal list of just usernames, you probably want something like:

authorized\_key: user=“{{ item }}” key=“{{ lookup(‘file’, ‘public-keys/’ + item + ‘.pub’) }}”  
with\_items: list\_of\_my\_users\_obtained\_earlier

I noticed several syntax issues. Such as using {{ }} inside of other {{ }}, which is not needed or allowed. Missing quotes around your path in the lookup. A missing space between ‘-’ and ‘list\_of\_my\_users\_obtained\_earlier’, which is not actually needed, you can just give the list on the same line was with\_items. You were using ‘item’ in one place, but ‘item.1’ in another.

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [October 3, 2014, 11:44am UTC](https://forum.ansible.com/t/ssh-keys/16404/3 "2014-10-03T11:44:50Z")

</div>

Hi Matt,

I’m aware of the syntax issues; I quickly wrote those two lines from the back of my head without verifying their syntax; sloppy really.  
What I didn’t know though was the way you concatenated the strings; should have known though, it’s python after all.

Anyway, thanks the provided solution helped me to implement what I wanted.
