-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" ] 
1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this really helps. I did make it work something like this set_fact: ip_addresses : "{{ ip_addresses | default([]) }} + [ '{{ item[0] }}' ]" with_items: "{{ LIST }}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.