# authorized\_key module not working

**URL:** <https://forum.ansible.com/t/authorized-key-module-not-working/20662>\
**Category:** Ansible Project\
**Created:** [February 23, 2016, 6:48pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662 "2016-02-23T18:48:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrono](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@chrono](https://forum.ansible.com/u/chrono)\
**Post date:** [February 23, 2016, 6:48pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662/1 "2016-02-23T18:48:35Z")

</div>

Hello,

I wrote a playbook that checks out brand new servers that are built for my team. To make things truly one-and-done, I thought it would be clever to include a play that copies the ssh public key from our ansible controller to the freshly built remote hosts.

I tried using the authorized\_key module, but it doesn’t seem to work…

Here is the play:

`

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [February 23, 2016, 7:32pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662/2 "2016-02-23T19:32:24Z")

</div>

Try with '-vvvv' for starters, and compare with SSHing with the  
servers directly.

---

<div class="post-metadata">

**Author:** ![chrono](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@chrono](https://forum.ansible.com/u/chrono)\
**Post date:** [February 23, 2016, 9:01pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662/3 "2016-02-23T21:01:59Z")

</div>

I’ve been looking at the -vvvv output and it doesn’t really help.

I guess I should ask this question… Does this module work for copying over the initial key? Or does it only work if there is already an ssh-key set up for ansible to use?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 23, 2016, 9:07pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662/4 "2016-02-23T21:07:20Z")

</div>

It does not need a key but it DOES need a way to login, normally user/password if keys are not available.

The other option is a super user that already has access can copy the keys for the specific users. Some cloud APIs allow for pushing a key through alternate methods, this module does not know about that (look at cloud specific modules for that).

---

<div class="post-metadata">

**Author:** ![chrono](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@chrono](https://forum.ansible.com/u/chrono)\
**Post date:** [February 24, 2016, 2:23pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662/5 "2016-02-24T14:23:51Z")

</div>

Interesting, then I am really out of ideas!

Here is the -vvvv output, maybe it will help diagnose it…

`

`TASK [setup] ******************************************************************* <hostnameRedacted> ESTABLISH SSH CONNECTION FOR USER: blah <hostnameRedacted> SSH: EXEC sshpass -d15 ssh -C -vvv -o ControlMaster=no -o StrictHostKeyChecking=no -o User=blah -o ConnectTimeout=10 -tt hostnameRedacted '( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1456322107.72-78449809147758 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1456322107.72-78449809147758 )" )' <hostnameRedacted> PUT /tmp/tmpuNYYso TO /home/blah/.ansible/tmp/ansible-tmp-1456322107.72-78449809147758/setup <hostnameRedacted> SSH: EXEC sshpass -d15 sftp -b - -C -vvv -o ControlMaster=no -o StrictHostKeyChecking=no -o User=blah -o ConnectTimeout=10 '[hostnameRedacted]' fatal: [hostnameRedacted]: UNREACHABLE! => {"changed": false, "msg": "ERROR! SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}`

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 24, 2016, 2:38pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662/6 "2016-02-24T14:38:16Z")

</div>

is sftp allowed on those machines? you might want to try setting scp\_if\_ssh to True in ansible.cfg if that is the case.

The fact that it does not fail on directory creation but it does at the PUT is a good hint of that.

---

<div class="post-metadata">

**Author:** ![chrono](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@chrono](https://forum.ansible.com/u/chrono)\
**Post date:** [February 24, 2016, 6:18pm UTC](https://forum.ansible.com/t/authorized-key-module-not-working/20662/7 "2016-02-24T18:18:47Z")

</div>

That did it!

Thank you!
