YAML refs aren't dereferenced in local Pillars #53291
Labels
Bug
broken, incorrect, or confusing behavior
Confirmed
Salt engineer has confirmed bug/feature - often including a MCVE
severity-medium
3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone
Description of Issue/Question
When using YAML refs/anchors in Pillar SLS of a local/masterless setup, refs aren't de-referenced before passing them into other contexts which leads to some quite unexpected results e.g. when processing those Pillar data further in a Jinja context, where updating a value within the data suddenly changes other data as well, as they all share the same referenced object.
Setup
State Template:
bug.sls
:Steps to Reproduce Issue
When using
bug.sls
provided above with the line{% set projects = yaml_input['projects'] %}
not commented out ({# ... #}
), the output generated bysalt-call slsutil.renderer salt://bug.sls
looks correct/as expected:When using the inlined YAML as Pillar SLS instead and commenting out the line
{% set projects = yaml_input['projects'] %}
again, the result looks like this (please note the non-matching elements (d
ina
,d
inb
):This indicates that YAML refs are simply passed through as Python references up to the point where Jinja processes the data of the dictionary, so instead of working on loop-scoped data in Jinja, one actually processes referenced data crossing loop-scope boundaries.
This can be reproduced using this Python-only code-snippet:
Output:
The output shows a few things:
SerializerExtension.load_yaml
fromsalt.utils.jinja
provides a regular dictionary and works as expectedrender
fromsalt.renderers.yaml
doesn't work as expected and provides anOrderedDictionary
(viasalt.utils.odict
).OrderedDictionary
usingcopy.deepcopy
doesn't work, but I'm not sure whether that's a general problem ofOrderedDictionary
or due to the custom Py27/Py3 compatibility layer insalt.utils.odict
In the end, I want to be able to simply not having to care about implementation internals when processing YAML/Pillar data in a Renderer/Jinja context - I expect Pillar data to be fully de-referenced when working with them.
Versions Report
Also reproduced in
2018.3.3
.The text was updated successfully, but these errors were encountered: