# Fetch public key of host A and put it in .ssh/authorized\_keys of host B

**URL:** <https://forum.ansible.com/t/fetch-public-key-of-host-a-and-put-it-in-ssh-authorized-keys-of-host-b/13209>\
**Category:** Ansible Project\
**Created:** [July 29, 2013, 6:53am UTC](https://forum.ansible.com/t/fetch-public-key-of-host-a-and-put-it-in-ssh-authorized-keys-of-host-b/13209 "2013-07-29T06:53:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Candeira](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@Javier\_Candeira](https://forum.ansible.com/u/Javier_Candeira)\
**Post date:** [July 29, 2013, 6:53am UTC](https://forum.ansible.com/t/fetch-public-key-of-host-a-and-put-it-in-ssh-authorized-keys-of-host-b/13209/1 "2013-07-29T06:53:49Z")

</div>

Each one of our customers has at least two hosts, A and B. The public  
ssh key for user foo on A has to be on authorized\_keys of user foo on  
B.

How to ensure this gets done on one run? The jobs are launched in  
parallell, and we have no guarantee that the playbook run on A will  
have fetched the key by the time the playbook run on B attempts to  
upload it.

Thanks,

Javier

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [July 29, 2013, 8:03am UTC](https://forum.ansible.com/t/fetch-public-key-of-host-a-and-put-it-in-ssh-authorized-keys-of-host-b/13209/2 "2013-07-29T08:03:18Z")

</div>

I’d say you would have to make two plays in 1 playbook.

Play 1 would create the desired user and create it’s ssh-keys.  
It would also copy it’s keys to a local folder.

Play 2 would then distribute that key to all other servers that need it.

---

<div class="post-metadata">

**Author:** ![Javier\_Candeira](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@Javier\_Candeira](https://forum.ansible.com/u/Javier_Candeira)\
**Post date:** [July 29, 2013, 8:13am UTC](https://forum.ansible.com/t/fetch-public-key-of-host-a-and-put-it-in-ssh-authorized-keys-of-host-b/13209/3 "2013-07-29T08:13:38Z")

</div>

Of course, thanks.

J
