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

Fail when duplicate key

How can I configure Ansible to assert duplicate keys?

I don’t want to rely on ANSIBLE_DUPLICATE_YAML_DICT_KEY , I’d like to assert this with a task.

Imagine this dict, which contains duplicate keys:

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

my_dict:
  one:
  one:

I’ve tried:

- assert:
    that:
      - my_dict | unique == my_dict

But this fails even when there are no duplicate keys.

>Solution :

This is not possible. Duplicate keys are discarded during parsing, so there is no way to detect that they were present once parsing is finished. Setting DUPLICATE_YAML_DICT_KEY to error is the only way to turn this into a failure.

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