-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jinja rendering of state .sls fails if pillar data ends with :
#53501
Comments
Hi @r-pufky see if making this change is what you need...
where I added file.replace: |
My initial report was a bit unclear. Will go over in detail. TL;DR: yaml-like parameters need to be quoted, which limits the usage of using pillar data to define dynamic SLS representations. Relates to #1543 Dynamic SLS: Some SLS file: {%- for test, test_option in tests.items() %}
file_replace_{{ test }}:
file.replace:
{%- for key, value in test_option.items() %}
- {{ key }}: {{ value }}
{%- endfor %}
{%- endfor %} Pillar
Static SLS file with non-pillar data.This performs as expected. Any yaml-like data must be quoted for processing to work correctly. Static SLS file with pillar data.This performs as expected. Any yaml-like data must be quoted for processing to work correctly. Dynamic SLS file with pillar data.(original bug submission) -- breaking this down, this is working as expected. The only real way to fix this is to use jinja to detect the datatype that is being rendered and quote it as needed. It would be nice for this detection to automatically happen before hitting the renderer by default so that the exception cases (e.g. forcing a type cast when rendering) would require explicit use. For current implementation, this forces explicit casting for standard data, which makes the templating messy for basic usage. Maybe this should be an option that can be enabled on the salt-master. Fix: # Dynamically generated file.replace using pillar data.
{%- for test, test_option in tests.items() %}
file_replace_{{ test }}:
file.replace:
{%- for key, value in test_option.items() %}
{%- if value is string %}
- {{ key }}: '{{ value }}'
{%- else %}
- {{ key }}: {{ value }}
{%- endif %}
{%- endfor %}
{%- endfor -%}
|
I should note that a workaround is to store the entire file contents in pillar (in this case, GPG encrypted) and just write that to the file. However, this isn't preferred because it obfuscates any non-secret material in the file that could be configuration options, etc. |
:
Thanks for providing so much detail on this! After investigating and working through this with @waynew |
Thanks for the update; didn't even think about that. I've confirm that |
Description of Issue
When rendering a files.replace, the following error occurs if a trailing : is used in the search pattern:
Rendering SLS 'base:salt.master' failed: mapping values are not allowed
Setup
Steps to Reproduce Issue
During runtime this will fail with the above mentioned error.
Looking into the failure message (essentially reading it as salt is trying to interpret values in search pattern in the wrong context), removing the trailing : fixes the issue.
Works fine.
Versions Report
The text was updated successfully, but these errors were encountered: