thanks for the help, but that's not exactly what i am after.  i'm
attempting to avoid creating a third variable.  but maybe that's the
only way

On Mon, Apr 17, 2023 at 7:05 PM Vladimir Botka <[email protected]> wrote:
>
> On Mon, 17 Apr 2023 18:22:10 -0400
> Michael DiDomenico <[email protected]> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CABOsP2Pmw3WvTADjQDMxUincTONrW6bu8KrujRO9cHf-4kL7_Q%40mail.gmail.com.

Reply via email to