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:
my_dict:
one:
one:
I've tried:
- assert:
that:
- my_dict | unique == my_dict
But this fails even when there are no duplicate keys.
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.