# How to declare a list of lists of lists

**URL:** <https://forum.ansible.com/t/how-to-declare-a-list-of-lists-of-lists/33363>\
**Category:** Ansible Project\
**Created:** [July 9, 2020, 8:10pm UTC](https://forum.ansible.com/t/how-to-declare-a-list-of-lists-of-lists/33363 "2020-07-09T20:10:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Maag](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@John\_Maag](https://forum.ansible.com/u/John_Maag)\
**Post date:** [July 9, 2020, 8:10pm UTC](https://forum.ansible.com/t/how-to-declare-a-list-of-lists-of-lists/33363/1 "2020-07-09T20:10:44Z")

</div>

I need to set up a list of volume groups. for each volume group there will be an attribute name and an attribute state. under each volume group is a list of one or more volumes. For each volume, there are attributes name, size, file system type, and mount point. Under each volume is a list of one or more disks. for each disk there are attributes bdevice and cdevice to indicate /dev/sda or /dev/sda1.

Something like this:

disks:

- vgname: vg1  
state: present
- lvname: lv1  
mntp: /u01  
lvsize: 100G  
fstype: xfs  
disk:
- {device: /dev/sda, pvname: /dev/sda1}

but this doesn’t work. Lastly, I would like a technique to know how many elements of disks there are because if there is only one disk I do not want to use lvm.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [July 9, 2020, 10:15pm UTC](https://forum.ansible.com/t/how-to-declare-a-list-of-lists-of-lists/33363/2 "2020-07-09T22:15:27Z")

</div>

> - For each volume group there will be an attribute name and an attribute  
> &nbsp;&nbsp;state  
> - Under each volume group is a list of one or more volumes.  
> - For each volume, there are attributes name,  
> &nbsp;&nbsp;size, file system type, and mount point  
> - Under each volume is a list of one or more disks.  
> - for each disk there are attributes bdevice and cdevice to  
> &nbsp;&nbsp;indicate /dev/sda or /dev/sda1.
> 
> Something like this:
> 
> disks:  
> &nbsp;&nbsp;- vgname: vg1  
> &nbsp;&nbsp;&nbsp;&nbsp;state: present

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;volumes:

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- lvname: lv1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mntp: /u01  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvsize: 100G  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fstype: xfs  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;disk:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- device: /dev/sda  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pvname: /dev/sda1

The list of volumes must be an attribute too.

---

<div class="post-metadata">

**Author:** ![John\_Maag](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@John\_Maag](https://forum.ansible.com/u/John_Maag)\
**Post date:** [July 9, 2020, 11:05pm UTC](https://forum.ansible.com/t/how-to-declare-a-list-of-lists-of-lists/33363/3 "2020-07-09T23:05:21Z")

</div>

Is there a way to walk **volumes** and **disk** lists? I can only find examples of walking **disks** and **volumes** with the subelements construct. Sorry there is both a disk and disks list construct.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [July 9, 2020, 11:44pm UTC](https://forum.ansible.com/t/how-to-declare-a-list-of-lists-of-lists/33363/4 "2020-07-09T23:44:10Z")

</div>

Yes. It is. Use "include\_tasks" in the loop with subelements volumes. In  
the included tasks loop "item.1.disk".

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [July 10, 2020, 12:06am UTC](https://forum.ansible.com/t/how-to-declare-a-list-of-lists-of-lists/33363/5 "2020-07-10T00:06:33Z")

</div>

> \> Is there a way to walk \*volumes\* and \*disk\* lists?

Try this loop

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ outer\_item.0.vgname }} {{ outer\_item.1.lvname }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ lookup('subelements', disks, 'volumes') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop\_control:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop\_var: outer\_item  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: "{{ outer\_item.0.vgname }}"

If it works then create a file to be included in the loop. For example

&nbsp;&nbsp;\> cat test.yml  
&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group [{{ outer\_item.0.vgname }}]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;volume [{{ outer\_item.1.lvname }}]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;device [{{ item.device }}]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pvname [{{ item.pvname }}]  
&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ outer\_item.1.disk }}"

and include it in the loop. For example

&nbsp;&nbsp;&nbsp;&nbsp;- include\_tasks: test.yml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ lookup('subelements', disks, 'volumes') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop\_control:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop\_var: outer\_item  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;label: "{{ outer\_item.0.vgname }}"

The result should be a list of messages with all combinations.
