authorized_key: Not creating .ssh directory - while saying success

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?

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

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.

Thanks Michael…

.raja