Prevent duplicate key warnings in `ansible.builtin.from_yaml`
Author: wtf9880Created Sep 24, 2026Updated Sep 28, 2026
Labelsneeds_triagehas_prfeature
Summary
I am trying to achieve something similar to this StackOverflow post, but specifically for the from_yaml filter.
In my Ansible playbook, I read a YAML file. Everything works as expected, but when I use YAML anchors like the following:
- &sometask
name: "Some Task"
some_module: with a lot of parameters
with_items: list_A
- <<: *sometask
name: "Some OTHER Task"
with_items: list_BI receive the following warning:
[WARNING]: Found duplicate mapping key 'name'.
Origin: <unknown>:14:5
name
Using last defined value only.
...I would like to be able to pass an optional argument to the from_yaml filter to control the behavior when duplicate keys exist. A good example would be this PR, which allows the behavior to be set to "ignore", "warn", or "error".
Issue Type
Feature Idea
Component Name
from_yaml
Additional Information
I think the summary section is clear and there is no need for additional information
Code of Conduct
- I agree to follow the Ansible Code of Conduct
Source: ansible/ansible