Search code examples
salt-project

saltstack and strange unicode quoting from pillar


I have some simple (ascii) pillar data that looks like this (somewhat simplified):

host:
  name:
    user: 'jeff'
    pass: 'sekret'

In a salt (sls) file, I invoke a jinja template like this:

{% set the_name = pillar.get('host')['name'] %}

/dev/null/myfile:
  file.managed:
    source: myfile_template
    ...
    -defaults:
       stuff: {{ the_name }

And in myfile_template, I refer to {{ stuff.user }}. I'm told stuff has no attribute 'user'. Same if I try {{ stuff["user"] }} or {{ stuff['user'] }}.

In salt 2018.3.2, this code worked. In salt 2019.2.0, this code does not work and I get the above error.

Simply inserting {{ stuff }} into the file (using salt 2019.2.0) says that the value is

{u"u'user'": u"u'jeff'", u"u'pass'": u"u'sekret'" }

I'm pretty sure that double unicode indicator is the sign of my problem, but I'm at a bit of a loss where it's coming from. Any suggestions what I might be doing wrong or what's changed?


Solution

  • As you stated than it worked in 2018.3 and not in 2019.2, you should have looked at the release notes for 2019.2 available there https://docs.saltstack.com/en/latest/topics/releases/2019.2.0.html.

    It explicitely mention a "Non-Backward-Compatible Change to YAML Renderer" here https://docs.saltstack.com/en/latest/topics/releases/2019.2.0.html#non-backward-compatible-change-to-yaml-renderer.

    You should change stuff: {{ the_name}} to stuff: {{ the_name|tojson }} if you plan to only use salt 2019.2, or stuff: {{ the_name|json }} if you plan to also be compatible with older releases.