# Multiple lines in subelements

**URL:** <https://forum.ansible.com/t/multiple-lines-in-subelements/15277>\
**Category:** Ansible Project\
**Created:** [May 20, 2014, 10:05am UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277 "2014-05-20T10:05:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joachim\_Friberg](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joachim\_Friberg](https://forum.ansible.com/u/Joachim_Friberg)\
**Post date:** [May 20, 2014, 10:05am UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277/1 "2014-05-20T10:05:46Z")

</div>

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

`

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 20, 2014, 10:14am UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277/2 "2014-05-20T10:14:15Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Joachim\_Friberg](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joachim\_Friberg](https://forum.ansible.com/u/Joachim_Friberg)\
**Post date:** [May 20, 2014, 10:17am UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277/3 "2014-05-20T10:17:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [May 20, 2014, 10:28am UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277/4 "2014-05-20T10:28:54Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Joachim\_Friberg](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joachim\_Friberg](https://forum.ansible.com/u/Joachim_Friberg)\
**Post date:** [May 20, 2014, 12:05pm UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277/5 "2014-05-20T12:05:21Z")

</div>

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

`

`

---

<div class="post-metadata">

**Author:** ![Ernest0x](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@Ernest0x](https://forum.ansible.com/u/Ernest0x)\
**Post date:** [May 20, 2014, 12:39pm UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277/6 "2014-05-20T12:39:54Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Joachim\_Friberg](https://avatars.discourse-cdn.com/v4/letter/j/6a8cbe/32.png) [@Joachim\_Friberg](https://forum.ansible.com/u/Joachim_Friberg)\
**Post date:** [May 20, 2014, 2:48pm UTC](https://forum.ansible.com/t/multiple-lines-in-subelements/15277/7 "2014-05-20T14:48:50Z")

</div>

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.
