New to ansible.

Trying to create a playbook to do the following:
1 Checks if a user exists and if not create
2 Check if /home/user/.ssh exists and if not create it
3 Copy ssh keys for the user

Having a problem with part 2

I have a variable file as follows
Ops:
 - User1:
   uname: user1
   passwd: ValidHash
 - User2:
   uname: user2
   passwd: ValidHash

Relevant part of playbook that is giving me trouble..
  - name: Attempt to check .ssh folder exists
    action: shell test -d /home/{{item['uname']}}/.ssh && echo “exists” || 
echo “”
    register: folder_exists
    with_items: Ops

  - name: Make .ssh folder for each user
    action: shell mkdir /home/{{item['uname']}}/.ssh
    with_items: Ops
    when: not folder_exists

The "when" check fails even though the  folders do not exist. Run with -vv
-----------------------
TASK: [Attempt to check .ssh folder exists] 
*********************************** 
<107.170.122.172> REMOTE_MODULE command test -d /home/user1/.ssh && echo 
“exists” || echo “” #USE_SHELL
changed: [ansible-test.wordjacktech.com] => (item={'passwd': 
'$6$rounds=100000$0mTt0BWi27Wkfbq.$nni86oU/8EIVswOll5o5YzxJzsKuy8Wx7im1VUhpWX/OMQsdhEoWV9vqrLJOpL8PWhgmFmQoqQTzqiqRqtXUh0',
 
'uname': 'user1', 'francisco': None}) => {"changed": true, "cmd": "test -d 
/home/freyes/.ssh && echo \u201cexists\u201d || echo \u201c\u201d ", 
"delta": "0:00:00.002813", "end": "2014-03-29 18:11:06.482901", "item": 
{"francisco": null, "passwd": 
"$6$rounds=100000$0mTt0BWi27Wkfbq.$nni86oU/8EIVswOll5o5YzxJzsKuy8Wx7im1VUhpWX/OMQsdhEoWV9vqrLJOpL8PWhgmFmQoqQTzqiqRqtXUh0",
 
"uname": "freyes"}, "rc": 0, "start": "2014-03-29 18:11:06.480088", 
"stderr": "", "stdout": ""}
<107.170.122.172> REMOTE_MODULE command test -d /home/user2/.ssh && echo 
“exists” || echo “” #USE_SHELL
changed: [ansible-test.wordjacktech.com] => (item={'passwd': 
'$6$rounds=100000$O.9Oyl0Xfar43LvS$X5P1RBXxwHBd4ktnq4sAmMLYkc8/m/WcS5hJKGqT/FQJYolSFHNSLrhfaiL4.dPtolM/p3aHOhMse88Cx.74G0',
 
'user2': None, 'uname': 'kelvin'}) => {"changed": true, "cmd": "test -d 
/home/kelvin/.ssh && echo \u201cexists\u201d || echo \u201c\u201d ", 
"delta": "0:00:00.002727", "end": "2014-03-29 18:11:08.438441", "item": 
{"kelvin": null, "passwd": 
"$6$rounds=100000$O.9Oyl0Xfar43LvS$X5P1RBXxwHBd4ktnq4sAmMLYkc8/m/WcS5hJKGqT/FQJYolSFHNSLrhfaiL4.dPtolM/p3aHOhMse88Cx.74G0",
 
"uname": "kelvin"}, "rc": 0, "start": "2014-03-29 18:11:08.435714", 
"stderr": "", "stdout": ""}

TASK: [Make .ssh folder for each user] 
**************************************** 
skipping: [ansible-test.wordjacktech.com] => (item={'passwd': 
'$6$rounds=100000$0mTt0BWi27Wkfbq.$nni86oU/8EIVswOll5o5YzxJzsKuy8Wx7im1VUhpWX/OMQsdhEoWV9vqrLJOpL8PWhgmFmQoqQTzqiqRqtXUh0',
 
'uname': 'user1', 'francisco': None})
skipping: [ansible-test.wordjacktech.com] => (item={'passwd': 
'$6$rounds=100000$O.9Oyl0Xfar43LvS$X5P1RBXxwHBd4ktnq4sAmMLYkc8/m/WcS5hJKGqT/FQJYolSFHNSLrhfaiL4.dPtolM/p3aHOhMse88Cx.74G0',
 
'user2': None, 'uname': 'kelvin'})
-----------------------

The .ssh folder is not getting created.
Tried changing from 
    when: not folder_exists
to
    when: folder_exists

and the folders get created. However on the second run it tries again to 
create the folders.
So either the folders are never created or try to be created every time. A 
little puzzled.

Any suggestions?

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f46678bd-d047-4758-8faa-d2b876f64aa8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to