Re: [ansible-project] merging lists

2023-04-17 Thread Vladimir Botka
On Mon, 17 Apr 2023 19:29:02 -0400
Michael DiDomenico  wrote:

> 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

You can avoid the third variable if you want to. For example,

  a: [1, 2, 3]
  b: "{{ a + [4, 5, 6] }}"

will add the lists

  b: [1, 2, 3, 4, 5, 6]

-- 
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/20230418070023.661358dd%40gmail.com.


pgpOQ29aUZfYl.pgp
Description: OpenPGP digital signature


Re: [ansible-project] merging lists

2023-04-17 Thread Michael DiDomenico
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  wrote:
>
> On Mon, 17 Apr 2023 18:22:10 -0400
> Michael DiDomenico  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/CABOsP2Pmw3WvTADjQDMxUincTONrW6bu8KrujRO9cHf-4kL7_Q%40mail.gmail.com.


Re: [ansible-project] merging lists

2023-04-17 Thread Vladimir Botka
On Mon, 17 Apr 2023 18:22:10 -0400
Michael DiDomenico  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.


pgpQ1CSW5eqn5.pgp
Description: OpenPGP digital signature


[ansible-project] merging lists

2023-04-17 Thread Michael DiDomenico
i want to do this, but i'm not getting exactly what i want

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' }

is there a way to merge the two lists?

-- 
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/CABOsP2N_wX5OuviQeXHzhTV%2BfGq%2BsOgHguTzy%3D%3Dh8v%3D5erx%2BHg%40mail.gmail.com.