authorized_key: Not creating .ssh directory - while saying success

463 views
Skip to first unread message

Raja Mukherjee

unread,
May 16, 2014, 4:52:22 PM5/16/14
to ansible...@googlegroups.com
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] *************************************************
<localhost> REMOTE_MODULE authorized_key user="mimi" key="" manage_dir=yes
<localhost> 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']
<localhost> PUT /tmp/tmpp3ljsQ TO /home/raja/.ansible/tmp/ansible-tmp-1400271971.73-135477642264398/authorized_key
<localhost> 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?

Raja Mukherjee

unread,
May 16, 2014, 6:19:57 PM5/16/14
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
May 18, 2014, 11:16:43 PM5/18/14
to ansible...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a30277c9-800d-47c8-a8e2-8de2b94d3a41%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Raja Mukherjee

unread,
May 19, 2014, 10:01:37 AM5/19/14
to ansible...@googlegroups.com
Thanks Michael...

.raja
Reply all
Reply to author
Forward
0 new messages