Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ansible – create list out of with_items

How can I create a list out of with_items? I tried the following but it records only the last group ID instead of creating a list.

  - name: "Generate list"
    set_fact:
      my_new_list: "{{ [ item.group_id  ] }}" 
    with_items:
      - "{{ec2_info.instances[0].security_groups}}"

ec2_info.instances[0].security_groups has multiple group_id’s.

                            "security_groups": [
                                {
                                    "group_id": "sg-0500c5b20f7c152b4",
                                    "group_name": "ManageIQ"
                                },
                                {
                                    "group_id": "sg-062178ea5fabaf350",
                                    "group_name": "launch-wizard-1"
                                }
                            ],

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

this playbook traps all the list:

 - name: "Generate list"
    set_fact:
      my_new_list: "{{ my_new_list|d([]) + [ item.group_id  ] }}" 
    with_items:
      - "{{ec2_info.instances[0].security_groups}}"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading