Salt: keyError on pillar.get

Created on 8 Jun 2018  路  2Comments  路  Source: saltstack/salt

I needed to throw exception on a missing key in pillar.get in jinja sls
Yet too many formulas start to fail on pillar_raise_on_missing set in minion config.
I have tried to set exceptions.KeyError in the sls formula but however I write it it returns jinja parse error.

Can I make pillar.get to throw exception on missing key, other than pillar_raise_on_missing in minion config.
Or alternatively is it possible to check if key is defined?

Salt Version:
Salt: 2018.3.0

Dependency Versions:
cffi: 1.11.4
cherrypy: Not Installed
dateutil: 2.4.2
docker-py: Not Installed
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: Not Installed
Jinja2: 2.8
libgit2: 0.27.0
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: 2.18
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: 0.27.0
Python: 2.7.12 (default, Dec 4 2017, 14:50:18)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: 0.9.0
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4

System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.4.0-112-generic
system: Linux
version: Ubuntu 16.04 xenial

Question

Most helpful comment

you can set the pillar like so {{ pillar['foo']['bar']['baz'] }} and it should fail if the pillar does not exist. You will get an error similar to:

    Data failed to compile:
----------
    Rendering SLS 'base:test' failed: Jinja variable 'salt.pillar object' has no attribute 'doesnotexist'

All 2 comments

you can set the pillar like so {{ pillar['foo']['bar']['baz'] }} and it should fail if the pillar does not exist. You will get an error similar to:

    Data failed to compile:
----------
    Rendering SLS 'base:test' failed: Jinja variable 'salt.pillar object' has no attribute 'doesnotexist'

Thanks :)

Was this page helpful?
0 / 5 - 0 ratings