# loop and variables

**URL:** <https://forum.ansible.com/t/loop-and-variables/30162>\
**Category:** Ansible Developer\
**Created:** [April 22, 2019, 5:37pm UTC](https://forum.ansible.com/t/loop-and-variables/30162 "2019-04-22T17:37:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvmpedro](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@mvmpedro](https://forum.ansible.com/u/mvmpedro)\
**Post date:** [April 22, 2019, 5:37pm UTC](https://forum.ansible.com/t/loop-and-variables/30162/1 "2019-04-22T17:37:01Z")

</div>

Hi guys,

How are you?

I am new at Ansible and doing some great stuffs until now.

I have those variables:

asm\_disks:

- { device: ‘sdc’, asm\_disk\_name: ‘ASM\_GRID01’, asm\_diskgroup: ‘GRID01’, asm\_redundancy: ‘NORMAL’, separator: ‘,’ }

- { device: ‘sdd’, asm\_disk\_name: ‘ASM\_GRID02’, asm\_diskgroup: ‘GRID01’, asm\_redundancy: ‘NORMAL’, separator: ‘,’ }

- { device: ‘sde’, asm\_disk\_name: ‘ASM\_GRID03’, asm\_diskgroup: ‘GRID01’, asm\_redundancy: ‘NORMAL’, separator: ‘’ }

- { device: ‘sdf’, asm\_disk\_name: ‘ASM\_DATA01’, asm\_diskgroup: ‘DATA’, asm\_redundancy: ‘EXTERNAL’, separator: ‘’ }

- { device: ‘sdg’, asm\_disk\_name: ‘ASM\_FRA01’, asm\_diskgroup: ‘FRA’, asm\_redundancy: ‘EXTERNAL’, separator: ‘’ }

- { device: ‘sdh’, asm\_disk\_name: ‘ASM\_REDO01\_01’, asm\_diskgroup: ‘REDO01’, asm\_redundancy: ‘EXTERNAL’, separator: ‘,’ }

- { device: ‘sdi’, asm\_disk\_name: ‘ASM\_REDO01\_02’, asm\_diskgroup: ‘REDO01’, asm\_redundancy: ‘EXTERNAL’, separator: ‘’ }

- { device: ‘sdj’, asm\_disk\_name: ‘ASM\_REDO02\_01’, asm\_diskgroup: ‘REDO02’, asm\_redundancy: ‘EXTERNAL’, separator: ‘,’ }

- { device: ‘sdk’, asm\_disk\_name: ‘ASM\_REDO02\_02’, asm\_diskgroup: ‘REDO02’, asm\_redundancy: ‘EXTERNAL’, separator: ‘’ }

I need to do something like this:

A loop to concatenate the asm\_disk\_name variable using comma (,), I know that I need to use join(‘,’)

The challenge is:

I need to concatenate all of asm\_disk\_name using comma breaking by asm\_diskgroup. So, for example: when loop changes from REDO01 asm\_diskgroup to REDO02, I need to register in another variable.

My expected output:

redo01:  
‘ASM\_REDO01\_01’,‘ASM\_REDO01\_02’

redo02:

‘ASM\_REDO01\_01’,‘ASM\_REDO01\_02’

How can I do that?

Thank you!

Marcus

---

<div class="post-metadata">

**Author:** ![maxamillion](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/maxamillion/32/98_2.png) [@maxamillion](https://forum.ansible.com/u/maxamillion)\
**Post date:** [April 24, 2019, 3:48pm UTC](https://forum.ansible.com/t/loop-and-variables/30162/2 "2019-04-24T15:48:13Z")

</div>

> Hi guys,
> 
> How are you?
> 
> I am new at Ansible and doing some great stuffs until now.
> 
> I have those variables:
> 
> asm\_disks:
> 
> &nbsp;&nbsp;- { device: 'sdc', asm\_disk\_name: 'ASM\_GRID01', asm\_diskgroup: 'GRID01', asm\_redundancy: 'NORMAL', separator: ',' }
> 
> &nbsp;&nbsp;- { device: 'sdd', asm\_disk\_name: 'ASM\_GRID02', asm\_diskgroup: 'GRID01', asm\_redundancy: 'NORMAL', separator: ',' }
> 
> &nbsp;&nbsp;- { device: 'sde', asm\_disk\_name: 'ASM\_GRID03', asm\_diskgroup: 'GRID01', asm\_redundancy: 'NORMAL', separator: '' }
> 
> &nbsp;&nbsp;- { device: 'sdf', asm\_disk\_name: 'ASM\_DATA01', asm\_diskgroup: 'DATA', asm\_redundancy: 'EXTERNAL', separator: '' }
> 
> &nbsp;&nbsp;- { device: 'sdg', asm\_disk\_name: 'ASM\_FRA01', asm\_diskgroup: 'FRA', asm\_redundancy: 'EXTERNAL', separator: '' }
> 
> &nbsp;&nbsp;- { device: 'sdh', asm\_disk\_name: 'ASM\_REDO01\_01', asm\_diskgroup: 'REDO01', asm\_redundancy: 'EXTERNAL', separator: ',' }
> 
> &nbsp;&nbsp;- { device: 'sdi', asm\_disk\_name: 'ASM\_REDO01\_02', asm\_diskgroup: 'REDO01', asm\_redundancy: 'EXTERNAL', separator: '' }
> 
> &nbsp;&nbsp;- { device: 'sdj', asm\_disk\_name: 'ASM\_REDO02\_01', asm\_diskgroup: 'REDO02', asm\_redundancy: 'EXTERNAL', separator: ',' }
> 
> &nbsp;&nbsp;- { device: 'sdk', asm\_disk\_name: 'ASM\_REDO02\_02', asm\_diskgroup: 'REDO02', asm\_redundancy: 'EXTERNAL', separator: '' }
> 
> I need to do something like this:
> 
> A loop to concatenate the asm\_disk\_name variable using comma (,), I know that I need to use join(',')
> 
> The challenge is:
> 
> I need to concatenate all of asm\_disk\_name using comma breaking by asm\_diskgroup. So, for example: when loop changes from REDO01 asm\_diskgroup to REDO02, I need to register in another variable.
> 
> My expected output:
> 
> redo01:  
> 'ASM\_REDO01\_01','ASM\_REDO01\_02'
> 
> redo02:  
> 'ASM\_REDO01\_01','ASM\_REDO01\_02'
> 
> How can I do that?

Hello and welcome!

This is an interesting problem to try and solve, but I think it's a  
topic better suited for the Ansible Users[0] mailing list as this list  
is meant for discussion about the development of Ansible itself and  
not that of playbooks or general Ansible use.

Thank you and happy automating! 🙂

-AdamM

[0] - [https://groups.google.com/forum/#!forum/ansible-project](https://groups.google.com/forum/#!forum/ansible-project)
