ansible/jinja2 get unique subelements

Viewed 4528

I got a list like this:

host_depends:
  - host: abc
    depends:
      - name: item1
      - name: item4
        type: asdf
      - name: item6
  - host: def
    depends:
      - name: item2
      - name: item4
      - name: item6

I need to loop over the unique name of the depends elemnents, so in this example I want to loop over

- item1 
- item2
- item4
- item6

Basically what

debug: var=item.1.name
with_subelements:
  - "{{ host_depends }}"
  - depends

does, but with unique elements only.

How can I get the depends of all host_depends items so I can run a unique filter over them and use them with with_items?

Edit:

I manage to get a list of all depends items like this:

host_depends|map(attribute='depends')|list

But from there, I fail to reduce this list to the name items.

3 Answers
Related