mardi 26 mars 2019

ansible: get list of subelements and assert for duplicates

Given a dictionary, assert for duplicates in the same list.

vars.yml file :

---
customer_domains:
  - name: myBank.org
  - name: myBakery.net
  - name: mySchool.edu
    smtp_username: smtp-school
    sender_domains:
      - sender1.tld
  - name: myRestaurant.net
  - name: myHouse.org
    smtp_relay_host: smtp-house.org
    smtp_relay_port: 25
    sender_domains:
      - test1.com
      - test1.com
      - test2.net
      - test3.house.net

What we really want is to make sure we don't have duplicate sender_domains for every name. Same sender_domains but in different names are allowed.

Doing a bit o research I was able to create the following task, which shows the value of sender_domains in every execution. However, what we really want is a list of all sender_domains from every name so we can assert for duplicates afterwards.

- name: DEBUG VAR=ITEM.1
  debug: var=item.1
  with_subelements:
    - ""
    - sender_domains

Thoughts?

This works to print subelements of customer_domains var:

- name: print customer_domains SUBELEMENTS
  debug:
    msg: ""
  with_subelements:
    - ""
    - sender_domains

Aucun commentaire:

Enregistrer un commentaire