-2

Need to flatten the array list FROM

[
    [
        [
            "10.11.33.11"
        ]
    ],
    [
        [
            "10.11.88.88"
        ]
    ]
]

TO

[ "10.11.33.11", "10.11.88.88" ] 
U880D
  • 8,601
  • 6
  • 24
  • 40
sam
  • 13
  • 1

1 Answers1

0

I understand your question as "How to manage list variables?

Since you have list of lists,

---
- hosts: localhost
  become: false
  gather_facts: false

  vars:
    LIST: [ [ ['10.11.33.11'] ],[ ['10.11.88.88'] ] ]

  tasks:

  - name: Show LIST flattened
    debug:
      msg: "{{ LIST | flatten(levels=2) }}"

you need need to address the level. Resulting into an output of

TASK [Show LIST flattened] *******
ok: [localhost] =>
  msg:
  - 10.11.33.11
  - 10.11.88.88

Background Information

if someone may be interested.

U880D
  • 8,601
  • 6
  • 24
  • 40
  • Thanks, this really helps. I did make it work something like this set_fact: ip_addresses : "{{ ip_addresses | default([]) }} + [ '{{ item[0] }}' ]" with_items: "{{ LIST }}" – sam Feb 14 '22 at 10:49