# Dynamically deploying multiple exclusive SSH authorized\_keys

**URL:** <https://forum.ansible.com/t/dynamically-deploying-multiple-exclusive-ssh-authorized-keys/20138>\
**Category:** Ansible Project\
**Created:** [January 7, 2016, 11:23am UTC](https://forum.ansible.com/t/dynamically-deploying-multiple-exclusive-ssh-authorized-keys/20138 "2016-01-07T11:23:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmacrae](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@cmacrae](https://forum.ansible.com/u/cmacrae)\
**Post date:** [January 7, 2016, 11:23am UTC](https://forum.ansible.com/t/dynamically-deploying-multiple-exclusive-ssh-authorized-keys/20138/1 "2016-01-07T11:23:51Z")

</div>

Hi all,

Further misunderstandings on my part for iterating over varied YAML structures, but here’s the deal:  
I’m writing a super tiny role with the intent of dynamically deploying any authorized\_keys defined in a host/group’s vars.  
That is to say, I need a task that will deploy keys to varied users, and the keys all need to be exclusive.

The use of files or templates will not suffice in this case - this needs to be scalable and in a sane structure.

Right now here’s the approach I’m taking.  
I have my keys defined like so:

`

---

<div class="post-metadata">

**Author:** ![Raghu\_Udiyar](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@Raghu\_Udiyar](https://forum.ansible.com/u/Raghu_Udiyar)\
**Post date:** [January 11, 2016, 6:36pm UTC](https://forum.ansible.com/t/dynamically-deploying-multiple-exclusive-ssh-authorized-keys/20138/2 "2016-01-11T18:36:21Z")

</div>

Try using with\_subelements [https://docs.ansible.com/ansible/playbooks\_loops.html#looping-over-subelements](https://docs.ansible.com/ansible/playbooks_loops.html#looping-over-subelements) and change the structure. Something like :

`

ssh\_authorized\_keys:

- root:
- foo
- other\_user:
- bar
- baz

`

---

<div class="post-metadata">

**Author:** ![cmacrae](https://avatars.discourse-cdn.com/v4/letter/c/2acd7d/32.png) [@cmacrae](https://forum.ansible.com/u/cmacrae)\
**Post date:** [January 11, 2016, 7:14pm UTC](https://forum.ansible.com/t/dynamically-deploying-multiple-exclusive-ssh-authorized-keys/20138/3 "2016-01-11T19:14:31Z")

</div>

Awesome, thanks Raghu! This definitely looks like the right approach. I’ll try this out and report back how I get on.
