salt icon indicating copy to clipboard operation
salt copied to clipboard

Can't access grains in salt state when declared in included config

Open Bilge opened this issue 14 years ago • 7 comments

By default a salt minion includes its config from files in /minion.d. However, if you elect to store grains in these files they will not be available to salt states. The grain appears when calling grains.item but raises an error when accessed by a salt state.

    Data failed to compile:
----------
    Rendering SLS failed, render error:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/salt/utils/templates.py", line 99, in jinja
    data = template.render(**passthrough)
  File "/usr/lib/python2.6/site-packages/jinja2/environment.py", line 891, in render
    return self.environment.handle_exception(exc_info, True)
  File "/var/cache/salt/files/base/users/users.sls", line 18, in top-level template code
    grains['foo']
UndefinedError: 'dict object' has no attribute 'foo'

Due to this it is also not possible to target custom grains in top.sls since the salt state will think they're not set.

Bilge avatar Nov 01 '12 14:11 Bilge

What do your config files look like? I imagine that the grains are being overwritten by multiple calls

thatch45 avatar Nov 01 '12 16:11 thatch45

They look like the default plus a grains.conf in minion.d.

Bilge avatar Nov 01 '12 17:11 Bilge

Ok, we will look into reproducing this, 0.10.4 I assume?

thatch45 avatar Nov 01 '12 17:11 thatch45

10.3

Bilge avatar Nov 01 '12 18:11 Bilge

upgrade to 0.10.4 . or un-comment line in /etc/salt/minion (if still using 0.10.3)

default_include: minion.d/*.conf

see if that works. there was a bug in 0.10.3, that was fixed in 0.10.4

mlister2006 avatar Nov 02 '12 04:11 mlister2006

Uncommenting the default_include line fixed it on 10.3. I can't upgrade to 10.4 yet because my mirror doesn't have it.

Bilge avatar Nov 02 '12 10:11 Bilge

Sounds good, I will close this out then, thanks @mlister2006 !

thatch45 avatar Nov 02 '12 15:11 thatch45