loop and variables

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

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?

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! :slight_smile:

-AdamM

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