Also apologies, I was offline for a bit and then had other priorities at 
work.

I've downloaded your github example as a zip file, unpacked it, modified 
host and usernames to reflect the local situation.

I now don't get an error, but now the tasks just show "skipping" for 
everything:

PLAY [Add sysadmins group and users] 
****************************************** 

GATHERING FACTS 
*************************************************************** 
ok: [host2]
ok: [host1]

TASK: [groups_users | Add groups] 
********************************************* 
skipping: [host1] => (item={'state': 'present', 'gid': 7575, 'name': 
'impulsys'})
skipping: [host2] => (item={'state': 'present', 'gid': 7575, 'name': 
'impulsys'})

TASK: [groups_users | Add users] 
********************************************** 
skipping: [host1] => (item={'comment': 'Paul Slootman 2', 'state': 
'present', 'group': 'groupname', 'name': 'pslootman', 'password': 
'$1$.xxxxxxxxxxxxxxxxxxxxxx', 'pubkey': 'ssh-rsa AAAA....', 'uid': 54343})
skipping: [host2] => (item={'comment': 'Paul Slootman 2', 'state': 
'present', 'group': 'groupname', 'name': 'pslootman', 'password': 
'$1$.xxxxxxxxxxxxxxxxxxxxxx', 'pubkey': 'ssh-rsa AAAA....', 'uid': 54343})

PLAY [Add db group and users] 
************************************************* 

GATHERING FACTS 
*************************************************************** 
ok: [host1]
ok: [host2]

TASK: [groups_users | Add groups] 
********************************************* 
skipping: [host1] => (item={'state': 'present', 'gid': 7576, 'name': 
'dbagroup'})
skipping: [host2] => (item={'state': 'present', 'gid': 7576, 'name': 
'dbagroup'})

TASK: [groups_users | Add users] 
********************************************** 
skipping: [host1] => (item={'comment': 'Nelson DBA', 'state': 'present', 
'group': 'dbagroup', 'name': 'ndba', 'password': '$1$.xxxxxxxxxxxxxxxxxxxxxx', 
'pubkey': None, 'uid': 54331})
skipping: [host2] => (item={'comment': 'Nelson DBA', 'state': 'present', 
'group': 'dbagroup', 'name': 'ndba', 'password': '$1$.xxxxxxxxxxxxxxxxxxxxxx', 
'pubkey': None, 'uid': 54331})

PLAY RECAP 
******************************************************************** 
host1                      : ok=6    changed=0    unreachable=0    failed=0 
  
host2                      : ok=6    changed=0    unreachable=0    failed=0 
  

I've modified roles/groups_users/tasks/main.yml to this:

---
- name: Add groups
  group: name={{ item.name }} gid={{ item.gid }} state={{ item.state }}
  with_items: unix_groups

- name: Add users
  user: name={{ item.name }}
        uid={{ item.uid }}
        password={{ item.password }}
        group={{ item.group }}
        groups=""
        comment="{{ item.comment }}"
        state={{ item.state }}
        update_password=always
        shell=/bin/bash
  with_items: unix_users

i.e. added extra fields and renamed "groups" and "users" to "unix_groups" 
and "unix_users". This is reflected by corresponding changes 
to external_vars/groups_users_db.yml 
and external_vars/groups_users_sysadmins.yml .

My problem is that I don't quite get how the group_vars/* files interact 
with roles stuff. I haven't had a lot of time to experiment with this yet, 
so perhaps it's something obvious but I didn't want to delay this response 
in case you thought I was ignoring you :-)

If it's something obvious to someone, please let me know. I'll continue 
trying it when I get time to spend on this.


thanks,
Paul


On Monday, 3 November 2014 21:48:06 UTC+1, mephage wrote:
>
> Hey Paul,
>
> My apologies for the delayed reply.
>
> I can't see why you're getting the result you are. But I did notice a few 
> errors in the snippets I posted. Here's a testing and working example:
>
> https://github.com/mephage/ansible-groups_users_example
>
> On Thursday, 30 October 2014 23:14:53 UTC+13, Paul Slootman wrote:
>>
>> Following up on myself:
>>
>> If I change the roles/groups_users/tasks/main.yml to this:
>>
>> ---
>> - name: Add groups
>>   group: name={{ item.name }}
>>   with_dict: groups
>>
>> - name: Add users
>>   user: name={{ item.name }}
>>         uid={{ item.uid }}
>>   with_items: users
>>
>> i.e. *with_dict* instead of *with_items* in the Add groups task, then I 
>> don't get an error. However the output of --check does not look like it is 
>> doing what I'd expect. Also why does the "Add users" task not need 
>> with_dict instead of "with_items"?!
>>
>> GATHERING FACTS 
>> ***************************************************************
>> ok: [host1]
>> ok: [host3]
>> ok: [host2]
>>
>> TASK: [groups_users | Add groups] 
>> ********************************************* 
>> skipping: [host1] => (item={'key': 'ungrouped', 'value': []})
>> skipping: [host1] => (item={'key': 'myhosts', 'value': ['host1', 'host2', 
>> 'host3']})
>> skipping: [host2] => (item={'key': 'ungrouped', 'value': []})
>> skipping: [host1] => (item={'key': 'all', 'value': ['host1', 'host2', 
>> 'host3']})
>> skipping: [host2] => (item={'key': 'myhosts', 'value': ['host1', 'host2', 
>> 'host3']})
>> skipping: [host1] => (item={'key': 'groups_users_db', 'value': ['host3']})
>> skipping: [host2] => (item={'key': 'all', 'value': ['host1', 'host2', 
>> 'host3']})
>> skipping: [host3] => (item={'key': 'ungrouped', 'value': []})
>> skipping: [host1] => (item={'key': 'groups_users_sysadmins', 'value': 
>> ['host1', 'host2', 'host3']})
>> skipping: [host2] => (item={'key': 'groups_users_db', 'value': ['host3']})
>> skipping: [host3] => (item={'key': 'myhosts', 'value': ['host1', 'host2', 
>> 'host3']})
>> skipping: [host2] => (item={'key': 'groups_users_sysadmins', 'value': 
>> ['host1', 'host2', 'host3']})
>> skipping: [host3] => (item={'key': 'all', 'value': ['host1', 'host2', 
>> 'host3']})
>> skipping: [host3] => (item={'key': 'groups_users_db', 'value': ['host3']})
>> skipping: [host3] => (item={'key': 'groups_users_sysadmins', 'value': 
>> ['host1', 'host2', 'host3']})
>>
>> TASK: [groups_users | Add users] 
>> ********************************************** 
>> skipping: [host1] => (item={'name': 'username3', 'uid': 3456})
>> skipping: [host1] => (item={'name': 'username4', 'uid': 4567})
>> skipping: [host3] => (item={'name': 'username3', 'uid': 3456})
>> skipping: [host2] => (item={'name': 'username3', 'uid': 3456})
>> skipping: [host3] => (item={'name': 'username4', 'uid': 4567})
>> skipping: [host2] => (item={'name': 'username4', 'uid': 4567})
>>
>> PLAY RECAP 
>> ******************************************************************** 
>> host1                     : ok=6    changed=0    unreachable=0   
>>  failed=0    
>> host2                     : ok=6    changed=0    unreachable=0   
>>  failed=0    
>> host3                     : ok=6    changed=0    unreachable=0   
>>  failed=0    
>>
>> This is shown twice (identical output), once for each play.
>>
>>
>> Paul
>>
>> On Thursday, 30 October 2014 09:41:48 UTC+1, Paul Slootman wrote:
>>>
>>> Thanks for your example, I'm just about understanding how it works :-) 
>>>  I did need to add a .yml extension to the external_vars/groups_users_* 
>>> files but that was obvious from how the playbook referenced those file. 
>>> Also the role needs "group:" and not "groups:" (the error message could 
>>> have been a bit clearer...).
>>>
>>> However, when I try this, the gathering facts works fine, then:
>>>
>>> TASK: [groups_users | Add groups] 
>>> ********************************************* 
>>> fatal: [host1] => with_items expects a list or a set
>>> fatal: [host2] => with_items expects a list or a set
>>> fatal: [host3] => with_items expects a list or a set
>>>
>>> FATAL: all hosts have already failed -- aborting
>>>
>>> This is the sort of thing that's probably trivial to fix with some 
>>> experience but I have no clue how to proceed now :-(
>>>
>>> FWIW I'm running:
>>> ansible 1.8 (devel 44afa7facc) last updated 2014/10/27 14:31:42 (GMT 
>>> +200)
>>>
>>

-- 
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/dd6c9ee9-7a87-4049-af6e-27e9c45bba30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to