Open DaAwesomeP opened 7 months ago
Loosely related to #33319
The error is due to invalid YAML. It has nothing to do with Jinja, thus {% raw %}
will do nothing re. escaping.
Instead of trying to put formatted YAML strings into your pillar, you should leave it as structural data and use file.serialize
, or render it with a template.
My difficultly is that the final file written to disk should have the raw Jinja templates preserved, not evaluated (this is a config file for an application that uses Jinja in YAML as well).
My understanding was that data in a |
in YAML is stored as a string, not YAML/dict. The error message shown indicated to me that it is being saved as a string but for some reason it is not escaping the contents properly?
I like the idea of simply making a template with {{ salt['pillar.get'] }}
as the contents. In that case, how do I stop Jinja from evaluating in the expressions in string in the pillar?
simply making a template with
{{ salt['pillar.get'] }}
as the contents
That is the same as using contents_pillar
.
How do I stop Jinja from evaluating in the expressions in string in the pillar?
With {% raw %}
, or changing the rendering pipeline for the whole file (e.g. #!yaml
at the top).
Your pillar is working fine, though is overly complicated. The problem is (I think) that you are iterating the values, not the keys. So your Jinja-rendered state has random chunks of YAML pasted into it.
Description Single quotation marks in a
{% raw %}
block inserted viacontents_pillar
are not escaped properly. See example below.Setup Pillar:
Salt:
Error:
Please be as specific as possible and give set-up details.
Steps to Reproduce the behavior See above configs.
Expected behavior Should insert file without error.
Screenshots N/A, see console output above.
Versions Report
salt --versions-report
```yaml Salt Version: Salt: 3006.6 Python Version: Python: 3.10.13 (main, Nov 15 2023, 04:34:27) [GCC 11.2.0] Dependency Versions: cffi: 1.14.6 cherrypy: unknown dateutil: 2.8.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 3.1.3 libgit2: 1.7.2 looseversion: 1.0.2 M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.2 msgpack-pure: Not Installed mysql-python: Not Installed packaging: 22.0 pycparser: 2.21 pycrypto: Not Installed pycryptodome: 3.19.1 pygit2: 1.14.1 python-gnupg: 0.4.8 PyYAML: 6.0.1 PyZMQ: 23.2.0 relenv: 0.14.2 smmap: Not Installed timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: debian 12 bookworm locale: utf-8 machine: x86_64 release: 6.1.0-18-amd64 system: Linux version: Debian GNU/Linux 12 bookworm ```Additional context Possibly an additional option like
contents_pillar_raw
would help?