Re: [ansible-project] merging lists

2023-04-18 Thread Vladimir Botka
On Tue, 18 Apr 2023 10:40:40 -0400
Todd Lewis  wrote:

>  - debug: msg="{{ [list_12, list_34, list_56] | sum(start=[]) }}"

Isn't *flatten* simpler?

  - debug: msg="{{ [list_12, list_34, list_56] | flatten }}"


-- 
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/20230418191211.7dc11ce0%40gmail.com.


pgp4SlUMvyE7j.pgp
Description: OpenPGP digital signature


Re: [ansible-project] merging lists

2023-04-18 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
And if you really wanted only unique list items this also works ...

- debug: msg="{{ [listb] | sum(start=lista) | unique }}"

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 12:44 PM, 'Rowe, Walter P. (Fed)' via Ansible Project 
 wrote:

I just tested and this also works.

- debug: msg="{{ [listb] | sum(start=lista) }}"

Walter

On Apr 18, 2023, at 11:01 AM, Michael DiDomenico  wrote:

agreed, brillant.  i'll give that a whirl, but it looks like exactly
what i'm after.  thanks

On Tue, Apr 18, 2023 at 10:40 AM Todd Lewis  wrote:

Also, by using the sum() filter:

[utoddl@tango ansible]$ cat foo.yml
---
- name: test lists
 become: false
 gather_facts: false
 hosts: localhost
 vars:
   list_12:
 - { one: 'str1', two: 'str2' }
   list_34:
 - { three: 'str3', four: 'str4' }
   list_56:
 - { five: 'str5', six: 'str6' }
 tasks:
   - debug: msg="[ {{ list_12, list_34, list_56 }} ]"
   - debug: msg="{{ [list_12, list_34, list_56] | sum(start=[]) }}"

[utoddl@tango ansible]$ ansible-playbook foo.yml

PLAY [test lists] 
***

TASK [debug] 

ok: [localhost] => {
   "msg": [
   [
   [
   {
   "one": "str1",
   "two": "str2"
   }
   ],
   [
   {
   "four": "str4",
   "three": "str3"
   }
   ],
   [
   {
   "five": "str5",
   "six": "str6"
   }
   ]
   ]
   ]
}

TASK [debug] 

ok: [localhost] => {
   "msg": [
   {
   "one": "str1",
   "two": "str2"
   },
   {
   "four": "str4",
   "three": "str3"
   },
   {
   "five": "str5",
   "six": "str6"
   }
   ]
}

PLAY RECAP 
**
localhost  : ok=2changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0


On 4/18/23 9:10 AM, 'Rowe, Walter P. (Fed)' via Ansible Project wrote:


% cat foo.yml

---

- name: test lists

 become: false

 gather_facts: false

 hosts: localhost

 vars:

   lista:

 - { one: 'str1', two: 'str2' }


   listb:

 - { three: 'str3', four: 'str4' }

 tasks:

   - debug: var=lista

   - debug: var=listb

   - set_fact:

   listb: [ "{{ lista + listb }}" ]

   - debug: var=listb




% ansible-playbook foo.yml


PLAY [test lists] 
**


TASK [debug] 
***

ok: [localhost] => {

   "lista": [

   {

   "one": "str1",

   "two": "str2"

   }

   ]

}


TASK [debug] 
***

ok: [localhost] => {

   "listb": [

   {

   "four": "str4",

   "three": "str3"

   }

   ]

}


TASK [set_fact] 


ok: [localhost]


TASK [debug] 
***

ok: [localhost] => {

   "listb": [

   [

   {

   "one": "str1",

   "two": "str2"

   },

   {

   "four": "str4",

   "three": "str3"

   }

   ]

   ]

}


PLAY RECAP 
*

localhost  : ok=4changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0



Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 9:07 AM, Michael DiDomenico  wrote:

On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:


TASK [debug] 
***
ok: [localhost] => {
  "listb": [
  [
  {
  "one": "str1",
  "two": "str2"
  },
  {
  "one": "str1",
  "two": "str2"
  }
  ]
  ]
}


i got to this point as well in my testing, but the double list
expansion of listb is a problem.

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

Re: [ansible-project] merging lists

2023-04-18 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
I just tested and this also works.

- debug: msg="{{ [listb] | sum(start=lista) }}"

Walter

On Apr 18, 2023, at 11:01 AM, Michael DiDomenico  wrote:

agreed, brillant.  i'll give that a whirl, but it looks like exactly
what i'm after.  thanks

On Tue, Apr 18, 2023 at 10:40 AM Todd Lewis  wrote:

Also, by using the sum() filter:

[utoddl@tango ansible]$ cat foo.yml
---
- name: test lists
 become: false
 gather_facts: false
 hosts: localhost
 vars:
   list_12:
 - { one: 'str1', two: 'str2' }
   list_34:
 - { three: 'str3', four: 'str4' }
   list_56:
 - { five: 'str5', six: 'str6' }
 tasks:
   - debug: msg="[ {{ list_12, list_34, list_56 }} ]"
   - debug: msg="{{ [list_12, list_34, list_56] | sum(start=[]) }}"

[utoddl@tango ansible]$ ansible-playbook foo.yml

PLAY [test lists] 
***

TASK [debug] 

ok: [localhost] => {
   "msg": [
   [
   [
   {
   "one": "str1",
   "two": "str2"
   }
   ],
   [
   {
   "four": "str4",
   "three": "str3"
   }
   ],
   [
   {
   "five": "str5",
   "six": "str6"
   }
   ]
   ]
   ]
}

TASK [debug] 

ok: [localhost] => {
   "msg": [
   {
   "one": "str1",
   "two": "str2"
   },
   {
   "four": "str4",
   "three": "str3"
   },
   {
   "five": "str5",
   "six": "str6"
   }
   ]
}

PLAY RECAP 
**
localhost  : ok=2changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0


On 4/18/23 9:10 AM, 'Rowe, Walter P. (Fed)' via Ansible Project wrote:


% cat foo.yml

---

- name: test lists

 become: false

 gather_facts: false

 hosts: localhost

 vars:

   lista:

 - { one: 'str1', two: 'str2' }


   listb:

 - { three: 'str3', four: 'str4' }

 tasks:

   - debug: var=lista

   - debug: var=listb

   - set_fact:

   listb: [ "{{ lista + listb }}" ]

   - debug: var=listb




% ansible-playbook foo.yml


PLAY [test lists] 
**


TASK [debug] 
***

ok: [localhost] => {

   "lista": [

   {

   "one": "str1",

   "two": "str2"

   }

   ]

}


TASK [debug] 
***

ok: [localhost] => {

   "listb": [

   {

   "four": "str4",

   "three": "str3"

   }

   ]

}


TASK [set_fact] 


ok: [localhost]


TASK [debug] 
***

ok: [localhost] => {

   "listb": [

   [

   {

   "one": "str1",

   "two": "str2"

   },

   {

   "four": "str4",

   "three": "str3"

   }

   ]

   ]

}


PLAY RECAP 
*

localhost  : ok=4changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0



Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 9:07 AM, Michael DiDomenico  wrote:

On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:


TASK [debug] 
***
ok: [localhost] => {
  "listb": [
  [
  {
  "one": "str1",
  "two": "str2"
  },
  {
  "one": "str1",
  "two": "str2"
  }
  ]
  ]
}


i got to this point as well in my testing, but the double list
expansion of listb is a problem.

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

Re: [ansible-project] merging lists

2023-04-18 Thread Michael DiDomenico
agreed, brillant.  i'll give that a whirl, but it looks like exactly
what i'm after.  thanks

On Tue, Apr 18, 2023 at 10:40 AM Todd Lewis  wrote:
>
> Also, by using the sum() filter:
>
> [utoddl@tango ansible]$ cat foo.yml
> ---
> - name: test lists
>   become: false
>   gather_facts: false
>   hosts: localhost
>   vars:
> list_12:
>   - { one: 'str1', two: 'str2' }
> list_34:
>   - { three: 'str3', four: 'str4' }
> list_56:
>   - { five: 'str5', six: 'str6' }
>   tasks:
> - debug: msg="[ {{ list_12, list_34, list_56 }} ]"
> - debug: msg="{{ [list_12, list_34, list_56] | sum(start=[]) }}"
>
> [utoddl@tango ansible]$ ansible-playbook foo.yml
>
> PLAY [test lists] 
> ***
>
> TASK [debug] 
> 
> ok: [localhost] => {
> "msg": [
> [
> [
> {
> "one": "str1",
> "two": "str2"
> }
> ],
> [
> {
> "four": "str4",
> "three": "str3"
> }
> ],
> [
> {
> "five": "str5",
> "six": "str6"
> }
> ]
> ]
> ]
> }
>
> TASK [debug] 
> 
> ok: [localhost] => {
> "msg": [
> {
> "one": "str1",
> "two": "str2"
> },
> {
> "four": "str4",
> "three": "str3"
> },
> {
> "five": "str5",
> "six": "str6"
> }
> ]
> }
>
> PLAY RECAP 
> **
> localhost  : ok=2changed=0unreachable=0failed=0   
>  skipped=0rescued=0ignored=0
>
>
> On 4/18/23 9:10 AM, 'Rowe, Walter P. (Fed)' via Ansible Project wrote:
>
>
> % cat foo.yml
>
> ---
>
> - name: test lists
>
>   become: false
>
>   gather_facts: false
>
>   hosts: localhost
>
>   vars:
>
> lista:
>
>   - { one: 'str1', two: 'str2' }
>
>
> listb:
>
>   - { three: 'str3', four: 'str4' }
>
>   tasks:
>
> - debug: var=lista
>
> - debug: var=listb
>
> - set_fact:
>
> listb: [ "{{ lista + listb }}" ]
>
> - debug: var=listb
>
>
>
>
> % ansible-playbook foo.yml
>
>
> PLAY [test lists] 
> **
>
>
> TASK [debug] 
> ***
>
> ok: [localhost] => {
>
> "lista": [
>
> {
>
> "one": "str1",
>
> "two": "str2"
>
> }
>
> ]
>
> }
>
>
> TASK [debug] 
> ***
>
> ok: [localhost] => {
>
> "listb": [
>
> {
>
> "four": "str4",
>
> "three": "str3"
>
> }
>
> ]
>
> }
>
>
> TASK [set_fact] 
> 
>
> ok: [localhost]
>
>
> TASK [debug] 
> ***
>
> ok: [localhost] => {
>
> "listb": [
>
> [
>
> {
>
> "one": "str1",
>
> "two": "str2"
>
> },
>
> {
>
> "four": "str4",
>
> "three": "str3"
>
> }
>
> ]
>
> ]
>
> }
>
>
> PLAY RECAP 
> *
>
> localhost  : ok=4changed=0unreachable=0failed=0   
>  skipped=0rescued=0ignored=0
>
>
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services, OISM
> Mobile: 202.355.4123
>
> On Apr 18, 2023, at 9:07 AM, Michael DiDomenico  
> wrote:
>
> On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
> Project  wrote:
>
>
> TASK [debug] 
> ***
> ok: [localhost] => {
>"listb": [
>[
>{
>"one": "str1",
>"two": "str2"
>},
>{
>"one": "str1",
>"two": "str2"
>}
>]
>]
> }
>
>
> i got to this point as well in my testing, but the double list
> expansion of listb is a problem.
>
> --
> 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 

Re: [ansible-project] merging lists

2023-04-18 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
Brilliant!

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 10:40 AM, Todd Lewis  wrote:

Also, by using the sum() filter:

[utoddl@tango ansible]$ cat foo.yml
---
- name: test lists
  become: false
  gather_facts: false
  hosts: localhost
  vars:
list_12:
  - { one: 'str1', two: 'str2' }
list_34:
  - { three: 'str3', four: 'str4' }
list_56:
  - { five: 'str5', six: 'str6' }
  tasks:
- debug: msg="[ {{ list_12, list_34, list_56 }} ]"
- debug: msg="{{ [list_12, list_34, list_56] | sum(start=[]) }}"

[utoddl@tango ansible]$ ansible-playbook foo.yml

PLAY [test lists] 
***

TASK [debug] 

ok: [localhost] => {
"msg": [
[
[
{
"one": "str1",
"two": "str2"
}
],
[
{
"four": "str4",
"three": "str3"
}
],
[
{
"five": "str5",
"six": "str6"
}
]
]
]
}

TASK [debug] 

ok: [localhost] => {
"msg": [
{
"one": "str1",
"two": "str2"
},
{
"four": "str4",
"three": "str3"
},
{
"five": "str5",
"six": "str6"
}
]
}

PLAY RECAP 
**
localhost  : ok=2changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0


On 4/18/23 9:10 AM, 'Rowe, Walter P. (Fed)' via Ansible Project wrote:

% cat foo.yml
---
- name: test lists
  become: false
  gather_facts: false
  hosts: localhost
  vars:
lista:
  - { one: 'str1', two: 'str2' }

listb:
  - { three: 'str3', four: 'str4' }
  tasks:
- debug: var=lista
- debug: var=listb
- set_fact:
listb: [ "{{ lista + listb }}" ]

- debug: var=listb




% ansible-playbook foo.yml

PLAY [test lists] 
**

TASK [debug] 
***
ok: [localhost] => {
"lista": [
{
"one": "str1",
"two": "str2"
}
]
}

TASK [debug] 
***
ok: [localhost] => {
"listb": [
{
"four": "str4",
"three": "str3"
}
]
}

TASK [set_fact] 

ok: [localhost]

TASK [debug] 
***
ok: [localhost] => {
"listb": [
[
{
"one": "str1",
"two": "str2"
},
{
"four": "str4",
"three": "str3"
}
]
]
}

PLAY RECAP 
*
localhost  : ok=4changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0


Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 9:07 AM, Michael DiDomenico 
 wrote:

On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
Project 
 
wrote:

TASK [debug] 
***
ok: [localhost] => {
   "listb": [
   [
   {
   "one": "str1",
   "two": "str2"
   },
   {
   "one": "str1",
   "two": "str2"
   }
   ]
   ]
}

i got to this point as well in my testing, but the double list
expansion of listb is a problem.

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

Re: [ansible-project] merging lists

2023-04-18 Thread Todd Lewis

Also, by using the sum() filter:

[utoddl@tango ansible]$ cat foo.yml
---
- name: test lists
  become: false
  gather_facts: false
  hosts: localhost
  vars:
list_12:
  - { one: 'str1', two: 'str2' }
list_34:
  - { three: 'str3', four: 'str4' }
list_56:
  - { five: 'str5', six: 'str6' }
  tasks:
- debug: msg="[ {{ list_12, list_34, list_56 }} ]"
- debug: msg="{{ [list_12, list_34, list_56] | sum(start=[]) }}"

[utoddl@tango ansible]$ ansible-playbook foo.yml

PLAY [test lists] 
***

TASK [debug] 

ok: [localhost] => {
"msg": [
[
[
{
"one": "str1",
"two": "str2"
}
],
[
{
"four": "str4",
"three": "str3"
}
],
[
{
"five": "str5",
"six": "str6"
}
]
]
]
}

TASK [debug] 

ok: [localhost] => {
"msg": [
{
"one": "str1",
"two": "str2"
},
{
"four": "str4",
"three": "str3"
},
{
"five": "str5",
"six": "str6"
}
]
}

PLAY RECAP 
**
localhost  : ok=2changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0


On 4/18/23 9:10 AM, 'Rowe, Walter P. (Fed)' via Ansible Project wrote:



*% cat foo.yml *

---

- name: test lists

become: false

gather_facts: false

hosts: localhost

vars:

lista:

- { one: 'str1', two: 'str2' }


*    listb:*

*      - { three: 'str3', four: 'str4' }*

tasks:

    - debug: var=lista

    - debug: var=listb

    - set_fact:

  listb: [ "{{ lista + listb }}" ]

    - debug: var=listb




*% ansible-playbook foo.yml*


PLAY [test lists] 
**



TASK [debug] 
***


ok: [localhost] => {

"lista": [

  {

      "one": "str1",

      "two": "str2"

  }

    ]

}


TASK [debug] 
***


ok: [localhost] => {

"listb": [

  {

      "four": "str4",

      "three": "str3"

  }

    ]

}


TASK [set_fact] 



ok: [localhost]


TASK [debug] 
***


ok: [localhost] => {

"listb": [

  [

      {

          "one": "str1",

          "two": "str2"

      },

      {

          "four": "str4",

          "three": "str3"

      }

  ]

    ]

}


PLAY RECAP 
*


localhost                  : ok=4 changed=0    unreachable=0    
failed=0    skipped=0 rescued=0    ignored=0




Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 9:07 AM, Michael DiDomenico 
 wrote:


On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:


TASK [debug] 
***

ok: [localhost] => {
   "listb": [
   [
   {
   "one": "str1",
   "two": "str2"
   },
   {
   "one": "str1",
   "two": "str2"
   }
   ]
   ]
}


i got to this point as well in my testing, but the double list
expansion of listb is a problem.

--
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://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCABOsP2O0HyQCBDnpJ5a2KK9RsUttdf6M0AgYcEFsZfGeJiMrww%2540mail.gmail.com=05%7C01%7Cwalter.rowe%40nist.gov%7C430da7c2101944514b5008db400de987%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638174200717509337%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=QplBJpgoUM2d3gQ9IZShI5aEwCPgx8A3bmw%2BFfIZyM8%3D=0.


--
You received this message because you are subscribed to the Google 
Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving 

Re: [ansible-project] merging lists

2023-04-18 Thread 'Rowe, Walter P. (Fed)' via Ansible Project

% cat foo.yml

---

- name: test lists

  become: false

  gather_facts: false

  hosts: localhost

  vars:

lista:

  - { one: 'str1', two: 'str2' }


listb:

  - { three: 'str3', four: 'str4' }

  tasks:

- debug: var=lista

- debug: var=listb

- set_fact:

listb: [ "{{ lista + listb }}" ]

- debug: var=listb




% ansible-playbook foo.yml


PLAY [test lists] 
**


TASK [debug] 
***

ok: [localhost] => {

"lista": [

{

"one": "str1",

"two": "str2"

}

]

}


TASK [debug] 
***

ok: [localhost] => {

"listb": [

{

"four": "str4",

"three": "str3"

}

]

}


TASK [set_fact] 


ok: [localhost]


TASK [debug] 
***

ok: [localhost] => {

"listb": [

[

{

"one": "str1",

"two": "str2"

},

{

"four": "str4",

"three": "str3"

}

]

]

}


PLAY RECAP 
*

localhost  : ok=4changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0


Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 9:07 AM, Michael DiDomenico  wrote:

On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:

TASK [debug] 
***
ok: [localhost] => {
   "listb": [
   [
   {
   "one": "str1",
   "two": "str2"
   },
   {
   "one": "str1",
   "two": "str2"
   }
   ]
   ]
}

i got to this point as well in my testing, but the double list
expansion of listb is a problem.

--
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://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCABOsP2O0HyQCBDnpJ5a2KK9RsUttdf6M0AgYcEFsZfGeJiMrww%2540mail.gmail.com=05%7C01%7Cwalter.rowe%40nist.gov%7C430da7c2101944514b5008db400de987%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638174200717509337%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=QplBJpgoUM2d3gQ9IZShI5aEwCPgx8A3bmw%2BFfIZyM8%3D=0.

-- 
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/6C71BFC3-34D5-4E2A-90E9-1CDB56B3CCE6%40nist.gov.


Re: [ansible-project] merging lists

2023-04-18 Thread 'Rowe, Walter P. (Fed)' via Ansible Project
This isn't a double expansion of listb. lista and listb happen to have the same 
values. change one of them and run the playbook to prove it.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 18, 2023, at 9:07 AM, Michael DiDomenico  wrote:

On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:

TASK [debug] 
***
ok: [localhost] => {
   "listb": [
   [
   {
   "one": "str1",
   "two": "str2"
   },
   {
   "one": "str1",
   "two": "str2"
   }
   ]
   ]
}

i got to this point as well in my testing, but the double list
expansion of listb is a problem.

--
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://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCABOsP2O0HyQCBDnpJ5a2KK9RsUttdf6M0AgYcEFsZfGeJiMrww%2540mail.gmail.com=05%7C01%7Cwalter.rowe%40nist.gov%7C430da7c2101944514b5008db400de987%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638174200717509337%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=QplBJpgoUM2d3gQ9IZShI5aEwCPgx8A3bmw%2BFfIZyM8%3D=0.

-- 
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/403537D8-0F35-46FD-870F-1D2C2B4E7830%40nist.gov.


Re: [ansible-project] merging lists

2023-04-18 Thread Michael DiDomenico
On Tue, Apr 18, 2023 at 8:56 AM 'Rowe, Walter P. (Fed)' via Ansible
Project  wrote:
>
> TASK [debug] 
> ***
> ok: [localhost] => {
> "listb": [
> [
> {
> "one": "str1",
> "two": "str2"
> },
> {
> "one": "str1",
> "two": "str2"
> }
> ]
> ]
> }

i got to this point as well in my testing, but the double list
expansion of listb is a problem.

-- 
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/CABOsP2O0HyQCBDnpJ5a2KK9RsUttdf6M0AgYcEFsZfGeJiMrww%40mail.gmail.com.


Re: [ansible-project] merging lists

2023-04-18 Thread 'Rowe, Walter P. (Fed)' via Ansible Project


---
- name: test lists
  become: false
  gather_facts: false
  hosts: localhost
  vars:
lista:
  - { one: 'str1', two: 'str2' }

listb:
 - { one: 'str1', two: 'str2' }
  tasks:
- debug: var=lista
- debug: var=listb
- set_fact:
listb: [ "{{ lista + listb }}" ]
- debug: var=listb


% ansible-playbook foo.yml

PLAY [test lists] 
**

TASK [debug] 
***
ok: [localhost] => {
"lista": [
{
"one": "str1",
"two": "str2"
}
]
}

TASK [debug] 
***
ok: [localhost] => {
"listb": [
{
"one": "str1",
"two": "str2"
}
]
}

TASK [set_fact] 

ok: [localhost]

TASK [debug] 
***
ok: [localhost] => {
"listb": [
[
{
"one": "str1",
"two": "str2"
},
{
"one": "str1",
"two": "str2"
}
]
]
}

PLAY RECAP 
*
localhost  : ok=4changed=0unreachable=0failed=0
skipped=0rescued=0ignored=0




Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Apr 17, 2023, at 6:22 PM, Michael DiDomenico  wrote:

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://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2FCABOsP2N_wX5OuviQeXHzhTV%252BfGq%252BsOgHguTzy%253D%253Dh8v%253D5erx%252BHg%2540mail.gmail.com=05%7C01%7Cwalter.rowe%40nist.gov%7C11c761941c2b4b87c06e08db3f923bbe%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638173669526803891%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C=F6cPYHsoFbMUJ8lWJKDuG2ym1o5eZLCrPId0qytWK3Y%3D=0.

-- 
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/474B3AA4-F21D-45B6-97EE-962E0F842B11%40nist.gov.


Re: [ansible-project] merging lists

2023-04-18 Thread Dick Visser
On Tue, 18 Apr 2023 at 00:22, Michael DiDomenico 
wrote:

> 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?
>

If lista will only ever contain a single item, then listb could be just

listb:
- "{{ lista[0] }}"
- { one: 'str1', two: 'str2' }

-- 
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/CAF8BbLY01xvU7Z-GU8yvNww9xF95JOw5Mst0UYuVgninwzXsww%40mail.gmail.com.


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.