salt: {{salt.pillar.get()}} / {{salt.grains.get()}} shorthand is broken
Description of Issue/Question
It’s not possible to use salt.pillar.get('something')
in state file.
Setup
Add a call to salt.pillar.get
to sls.
Steps to Reproduce Issue
Run the state (in here I can only reproducer with salt-ssh so far). The error is
Rendering exception occurred: Jinja error: get() takes exactly 3 arguments (2 given)
(same for pillar and grains)
salt['pillar.get']()
works as expected. I was able to workaround the issue with the following renderer prepended to jinja|yaml:
def render(data, saltenv='base', sls='', argline='', **kwargs):
data_str = data.read()
data_str = (data_str
.replace('salt.pillar.get(', 'salt["pillar.get"](')
.replace('salt.grains.get(', 'salt["grains.get"]('))
return StringIO(data_str)
Versions Report
Salt Version:
Salt: 2017.7.0-267-gcc72f1a
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.9.6
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.8
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.10 (default, Feb 7 2017, 00:08:15)
python-gnupg: Not Installed
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.5.1
ZMQ: 4.2.2
System Versions:
dist:
machine: x86_64
release: 16.6.0
system: Darwin
version: 10.12.5 x86_64
About this issue
- Original URL
- State: open
- Created 7 years ago
- Comments: 20 (14 by maintainers)
Links to this issue
Commits related to this issue
- Revert "Change Salt function invocation in Jinja" This is currently broken over Salt-SSH; reported at https://github.com/saltstack/salt/issues/41794 This reverts commit e89c9c68926363454bea0e43db2b3... — committed to jcu-eresearch/shared-salt-states by davidjb 7 years ago
- feat(map.jinja): homogeneous salt function call syntax Note that with some functions, the dot notation does not work with `salt-ssh` (see https://github.com/saltstack/salt/issues/41794). — committed to baby-gnu/template-formula by baby-gnu 4 years ago
- Replace salt.pillar.get with ugly salt['pillar.get'] as no supported by salt-ssh See bug in Salt: https://github.com/saltstack/salt/issues/41794 — committed to petrows/saltstack-config by petrows 3 years ago
That’s not a recommendation, just a statement. They’re explaining the difference between
pillar.get()
andsalt.pillar.get()
.But it’s not though, it’s a function call on some “pillar” object that’s an attribute of some “salt” object. And that “pillar” object is completely different to the injected
pillar
object.A function. You don’t see it in library APIs because you can use imports instead. But you do see it in Python code generally because it didn’t have any switch statements until 3.10.
No. It’s not going to help with
salt.pillar.get
either.Not sure what you were expecting.
pillar
is for all intents and purposes just a regular dict.They don’t. The
pillar
dict is the cache. It’ssalt["pillar.get"]
that bypasses it.You’ll get better performance if you use
pillar
. The advantage ofsalt["pillar.get"]
is the key traversal syntax.I’m able to reproduce this with the following test case:
This is only broken on salt-ssh and it is not a regression. I can see the same failed behavior all the way back in 2016.3 branch. We will need to get this fixed