On Mon, 17 Apr 2023 18:22:10 -0400
Michael DiDomenico <mdidomeni...@gmail.com> wrote:

> lista:
> - { one: 'str1', two: 'str2' }
> 
> listb:
> - "{{ lookup('vars','lista') }}"
> - { one: 'str1', two: 'str2' }
> 
> the output i want is
> 
> listb:
> { one: 'str1', two: 'str2' },
> { one: 'str1', two: 'str2' }
> 
> but what i get is
> 
> listb:
> [ { one: 'str1', two: 'str2' } ],
> { one: 'str1', two: 'str2' }

The lookup *vars* is not necessary. Reference the variable

  listb:
    - "{{ lista }}"
    - {one: str1, two: str2}

You should get

  listb:
    - - one: str1
        two: str2
    - one: str1
      two: str2

This is correct. The first item on the list *listb* is list *lista*.
If you put two items into the list *lista*

  lista:
    - one: str1
      two: str2
    - ccc: str3
      ddd: str4

you'll get

  listb:
    - - one: str1
        two: str2
      - ccc: str3
        ddd: str4
    - one: str1
      two: str2

You can *flatten* the list

   listc: "{{ listb|flatten }}"

gives

  listc:
    - one: str1
      two: str2
    - ccc: str3
      ddd: str4
    - one: str1
      two: str2

However, a simpler option is adding lists. For example, given two
lists

  lista:
    - {one: str1, two: str2}
    - {ccc: str3, ddd: str4}
  listb:
    - {one: str1, two: str2}

Declare the list *listc*. This will merge the two lists

  listc: "{{ lista + listb }}"


-- 
Vladimir Botka

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230418010528.33cdd05c%40gmail.com.

Attachment: pgpQ1CSW5eqn5.pgp
Description: OpenPGP digital signature

Reply via email to