# authorized\_key: Not creating .ssh directory - while saying success

**URL:** <https://forum.ansible.com/t/authorized-key-not-creating-ssh-directory-while-saying-success/15260>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [May 16, 2014, 8:52pm UTC](https://forum.ansible.com/t/authorized-key-not-creating-ssh-directory-while-saying-success/15260 "2014-05-16T20:52:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raja\_Mukherjee](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raja\_Mukherjee](https://forum.ansible.com/u/Raja_Mukherjee)\
**Post date:** [May 16, 2014, 8:52pm UTC](https://forum.ansible.com/t/authorized-key-not-creating-ssh-directory-while-saying-success/15260/1 "2014-05-16T20:52:22Z")

</div>

Platform:

raja@ansible-control:~/ansible$ cat /etc/lsb-release | grep -i desc | cut -d’=’ -f2  
“Ubuntu 14.04 LTS”

Ansible is installed through PPA

raja@ansible-control:~/ansible$ ansible --version  
ansible 1.6

**roles/user/vars/main.yml**

(for testing, eventually will go to group\_vars)

authorized:

- username: mimi  
ssh\_key\_files:
- id\_rsa\_mimi.pub

roles/users/tasks/main.yml (snippet)

- name: Copy SSH Keys  
authorized\_key: user=“{{ item.0.username }}”  
key=“{{ lookup(‘file’, ‘/keys/’ + item.0.username + ‘/’ + item.1) }}”  
with\_subelements:
- authorized
- ssh\_key\_files  
tags: ‘users’

Key file exists

raja@ansible-control:~/ansible$ ll roles/users/files/keys/mimi/  
total 16  
drwxrwxr-x 2 raja raja 4096 May 16 15:04 ./  
drwxrwxr-x 4 raja raja 4096 May 16 15:04 …/  
-rw-rw-r-- 1 raja raja 740 May 16 09:10 id\_rsa\_mimi.pub

When I run this, it says successful…

TASK: [users | Copy SSH Keys] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 REMOTE\_MODULE authorized\_key user=“mimi” key=“” manage\_dir=yes  
 EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1400271971.73-135477642264398 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1400271971.73-135477642264398 && echo $HOME/.ansible/tmp/ansible-tmp-1400271971.73-135477642264398’]  
 PUT /tmp/tmpp3ljsQ TO /home/raja/.ansible/tmp/ansible-tmp-1400271971.73-135477642264398/authorized\_key  
 EXEC /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=banwdhwvmsabmqjcjmygxjkmjbmztflf] password: " -u root /bin/sh -c '”’“‘echo SUDO-SUCCESS-banwdhwvmsabmqjcjmygxjkmjbmztflf; LC\_CTYPE=C LANG=C /usr/bin/python /home/raja/.ansible/tmp/ansible-tmp-1400271971.73-135477642264398/authorized\_key; rm -rf /home/raja/.ansible/tmp/ansible-tmp-1400271971.73-135477642264398/ \>/dev/null 2\>&1’”‘"’’  
ok: [localhost] =\> (item=({‘username’: ‘mimi’}, ‘id\_rsa\_mimi.pub’)) =\> {“changed”: false, “item”: [{“username”: “mimi”}, “id\_rsa\_mimi.pub”], “key”: “”, “key\_options”: null, “keyfile”: “/home/mimi/.ssh/authorized\_keys”, “manage\_dir”: true, “path”: null, “state”: “present”, “unique”: false, “user”: “mimi”}

However, it does not create .ssh directory or .ssh/authorized\_keys on the target machine/userHome…user is created as part of the same role/tasks, just prior to this task.

Any idea what’s going on?

---

<div class="post-metadata">

**Author:** ![Raja\_Mukherjee](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raja\_Mukherjee](https://forum.ansible.com/u/Raja_Mukherjee)\
**Post date:** [May 16, 2014, 10:19pm UTC](https://forum.ansible.com/t/authorized-key-not-creating-ssh-directory-while-saying-success/15260/2 "2014-05-16T22:19:57Z")

</div>

I figured it out…problem is that if lookup function does not find a file, it seems to not generate any error to upstream…my issue was…this line

key=“{{ lookup(‘file’, ‘/keys/’ + item.0.username + ‘/’ + item.1) }}”

it should be

key=“{{ lookup(‘file’, ‘keys/’ + item.0.username + ‘/’ + item.1) }}” - relative to the roles/files

I had a similar issue with copy and that’s what aided me to figure this out.

Thanks

.raja

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 19, 2014, 3:16am UTC](https://forum.ansible.com/t/authorized-key-not-creating-ssh-directory-while-saying-success/15260/3 "2014-05-19T03:16:43Z")

</div>

There should already be a ticket open about lookup module errors not resulting in errors that traverse down the stack.

This is currently flagged a “P2” so it should be included in the next dot release.

---

<div class="post-metadata">

**Author:** ![Raja\_Mukherjee](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raja\_Mukherjee](https://forum.ansible.com/u/Raja_Mukherjee)\
**Post date:** [May 19, 2014, 2:01pm UTC](https://forum.ansible.com/t/authorized-key-not-creating-ssh-directory-while-saying-success/15260/4 "2014-05-19T14:01:37Z")

</div>

Thanks Michael…

.raja
