---
- 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=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 17, 2023, at 6:22 PM, Michael DiDomenico <[email protected]> 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 [email protected].
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&data=05%7C01%7Cwalter.rowe%40nist.gov%7C11c761941c2b4b87c06e08db3f923bbe%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638173669526803891%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=F6cPYHsoFbMUJ8lWJKDuG2ym1o5eZLCrPId0qytWK3Y%3D&reserved=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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/474B3AA4-F21D-45B6-97EE-962E0F842B11%40nist.gov.

Reply via email to