# Getting ssh public key as a variable

**URL:** <https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365>\
**Category:** Ansible Project\
**Created:** [February 15, 2013, 10:08pm UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365 "2013-02-15T22:08:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kavin](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kavin](https://forum.ansible.com/u/Kavin)\
**Post date:** [February 15, 2013, 10:08pm UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365/1 "2013-02-15T22:08:05Z")

</div>

Hi,

So i am just trying to know the background on the reason behind having (_ansible\_ssh\_host\_key\_rsa\_public_) but not the _$HOME/.ssh/id\_rsa.pub_ variable for the user trying to get the facts ?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 15, 2013, 10:43pm UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365/2 "2013-02-15T22:43:40Z")

</div>

I don't understand, can you share more about what are you trying to do?

---

<div class="post-metadata">

**Author:** ![Kavin](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kavin](https://forum.ansible.com/u/Kavin)\
**Post date:** [February 15, 2013, 10:53pm UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365/3 "2013-02-15T22:53:07Z")

</div>

Sorry, I want to understand what is the best practice and what the community uses for the following:

if i have 3 servers, i want to make sure each of the 3 servers can login to each other with their public key. Say user X,

So the logic is simple, basically reading .pub from all 3 nodes and then either use template or use authorized\_keys to add all other public key to the authorized file.

Let me know if this sounds stupid,

Regards,–  
Kavin Kankeshwar

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 15, 2013, 11:10pm UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365/4 "2013-02-15T23:10:12Z")

</div>

Ah, interesting.

I would really prefer to see those SSH keys dispensed from the control  
node directly, rather than having one node tell another node who can  
log into another.

Seems potentially a mess that way.

---

<div class="post-metadata">

**Author:** ![Kavin](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kavin](https://forum.ansible.com/u/Kavin)\
**Post date:** [February 15, 2013, 11:19pm UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365/5 "2013-02-15T23:19:33Z")

</div>

Thanks for the reply,Sorry i might not have understood your comment,

Trying to clarify: Yes i mean to pull all public keys from nodes to my ansible node and then push out an entire list of SSH authorized keys .

I can easily solve this by sending everyone the same private key and have the same authorized keys 🙂 But i am trying to understand how to do some complex stuff with Ansible. 😃

Regards,–  
Kavin Kankeshwar

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 16, 2013, 1:13am UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365/6 "2013-02-16T01:13:14Z")

</div>

It's a little bit of a messy use case.

Such things are doable, but rather than asking to show you, you really  
should consider pushing the keys out centrally from an authorative  
source.

What you are asking to do is potentially dangerous as if you created a  
key on an untrusted box, you're making it automatically have access to  
the entire infrastructure.

I don't want to give the example of how to do that 🙂

---

<div class="post-metadata">

**Author:** ![Kavin](https://avatars.discourse-cdn.com/v4/letter/k/ba8739/32.png) [@Kavin](https://forum.ansible.com/u/Kavin)\
**Post date:** [February 16, 2013, 1:16am UTC](https://forum.ansible.com/t/getting-ssh-public-key-as-a-variable/12365/7 "2013-02-16T01:16:53Z")

</div>

Ok Thanks 🙂 Will push it out.

Regards,–  
Kavin Kankeshwar
