Multiple lines in subelements

Hi,

I’m trying to push the limits of “subelements” but I can’t figure out how…
Part of my task/main.yml

`

  • name: Prepare for Shinken|user
    user: name={{ item.0.name }}
    comment={{ item.0.comment }}
    group={{ item.0.group }}
    shell={{ item.0.shell }}
    password={{ item.0.password }}
    state=present
    update_password=on_create
    with_subelements:
  • users
  • group

`
my var/main.yml

`

You are using lists for every key (comment, group, shell, …) whereas with the subelements loop, you can only have a list for the group subkey (as per your task)

So what I’m trying to achive is not possible?
How could I create a set of users using the variable’s-file instead of “hardcoding” them into the task-file?

It doesn’t make sense to have a list of passwords, comments, shell, as only one value can apply etc?
Here it reall only makes sense for groups, no?

Try this:

You are the best! This should go in to the andible-docs.
I Just needed to modify it a small bit.
Here’s the end result and code:

`

  • name: Prepare for Shinken|user
    user: name={{ item.0.name }}
    comment={{ item.0.comment }}
    group={{ item.1 }}
    shell={{ item.0.shell }}
    password={{ item.0.password }}
    state=present
    update_password=on_create
    append=yes
    with_subelements:
  • users
  • group

`

`

I think the above loop is not correct for what you want to do. You are using the ‘group’ parameter of the user module, which sets the primary group. So, it will reset it on each loop iteration. Also, you are using a key named ‘group’ with a list value, which seems not to be indicative of what you want to deploy. What is it meant for? Is it meant to be a list of the groups the user must be member of? Then rename it to ‘groups’. Is it meant to be the primary group of the user? Then rename it to ‘primary_group’. In either case, it seems that what you want can be done with a simple ‘with_items’ loop. No need for a ‘with_subelements’ loop. For example:

Another great way of doing it!
What I’m going to do is just a playbook to setup the basic Shinken system. And the Shinken user should only be member of the group shinken.