salt: Problem with salt-ssh and mine.get
Description of Issue/Question
Under some circumstances highstate fails when using salt-ssh and salt['mine.get']
with error:
Jinja variable 'salt.utils.templates.AliasedLoader object' has no attribute 'grains.get'
Although I am able to successfully run each state individually, I get the above error when running highstate. The problem doesn’t occure if we:
- remove the block/state where
salt['mine.get']
is called - change the order of states in top.sls
Setup
Roster file:
murray2:
host: 10.10.10.56
user: dan
sudo: True
priv: ~/.ssh/dan.pem
thin_dir: /opt/salt-thin
mine_functions:
network.interfaces: []
grains.item:
- roles
- fqdn
- applications
- ip_interfaces
grains:
roles:
- backend
applications:
- chuck
states/test_hosts/init.sls:
/etc/hostname:
file.managed:
- contents: {{ salt['grains.get']('id') }}
{%- for host, data in salt['mine.get']('*', 'grains.item').items() %}
hostsfile_{{host}}:
host.present:
- names:
- {{host}}
- ip: {{data.ip_interfaces.eth0[0]}}
{% endfor%}
states/test_apps/init.sls
{%- for app in salt['grains.get']('applications',[]) %}
{%- set app_data = salt['pillar.get']('applications:%s' % app) %}
{%- from 'test_apps/macros.j2' import this_macro %}
/tmp/{{app}}:
file.managed:
- contents: {{ salt['disk.blkid']('')}}
{{this_macro(app)}}
{% endfor %}
states/top.sls:
base:
'*':
- test_hosts
- test_apps
Steps to Reproduce Issue
$ salt-ssh 'murray2' state.highstate
[ERROR ] Rendering exception occurred: Jinja variable 'salt.utils.templates.AliasedLoader object' has no attribute 'grains.get'
[CRITICAL] Rendering SLS 'base:test_apps' failed: Jinja variable 'salt.utils.templates.AliasedLoader object' has no attribute 'grains.get'
murray2:
- Rendering SLS 'base:test_apps' failed: Jinja variable 'salt.utils.templates.AliasedLoader object' has no attribute 'grains.get'
The last lines of the master.log are:
2016-10-05 17:19:03,239 [salt.template ][PROFILE ][6241] Time (in seconds) to render '/tmp/salt/files/base/test_hosts/init.sls' using 'yaml' renderer: 0.00873517990112
2016-10-05 17:19:03,240 [salt.fileclient ][DEBUG ][6241] Could not find file from saltenv 'base', 'salt://test_apps.sls'
2016-10-05 17:19:03,242 [salt.fileclient ][DEBUG ][6241] In saltenv 'base', looking at rel_path 'test_apps/init.sls' to resolve 'salt://test_apps/init.sls'
2016-10-05 17:19:03,243 [salt.fileclient ][DEBUG ][6241] In saltenv 'base', ** considering ** path '/tmp/salt/files/base/test_apps/init.sls' to resolve 'salt://test_apps/init.sls'
2016-10-05 17:19:03,243 [salt.fileclient ][DEBUG ][6241] Fetching file from saltenv 'base', ** attempting ** 'salt://test_apps/init.sls'
2016-10-05 17:19:03,243 [salt.fileclient ][DEBUG ][6241] No dest file found
2016-10-05 17:19:03,244 [salt.fileclient ][INFO ][6241] Fetching file from saltenv 'base', ** done ** 'test_apps/init.sls'
2016-10-05 17:19:03,244 [salt.template ][DEBUG ][6241] compile template: /tmp/salt/files/base/test_apps/init.sls
2016-10-05 17:19:03,245 [salt.utils.jinja ][DEBUG ][6241] Jinja search path: ['/opt/salt-thin/running_data/var/cache/salt/minion/files/base']
2016-10-05 17:19:03,256 [salt.utils.templates][ERROR ][6241] Rendering exception occurred: Jinja variable 'salt.utils.templates.AliasedLoader object' has no attribute 'grains.get'
2016-10-05 17:19:03,257 [salt.state ][CRITICAL][6241] Rendering SLS 'base:test_apps' failed: Jinja variable 'salt.utils.templates.AliasedLoader object' has no attribute 'grains.get'
2016-10-05 17:19:03,362 [salt.utils.lazy ][DEBUG ][6232] LazyLoaded nested.output
Lastly, highstate runs successfully if I change states order in states/top.sls:
base:
'*':
- test_apps
- test_hosts
Versions Report
Salt Version:
Salt: 2016.3.3
Dependency Versions:
cffi: Not Installed
cherrypy: Not Installed
dateutil: 2.5.3
gitdb: 0.6.4
gitpython: 1.0.1
ioflo: Not Installed
Jinja2: 2.8
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pygit2: Not Installed
Python: 2.7.12 (default, Jul 1 2016, 15:12:24)
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
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 22 (11 by maintainers)
Commits related to this issue
- Fix merge order of options in run_wfunc (fix mine.get issues) This fix issues with mine.get when using salt-ssh (https://github.com/saltstack/salt/issues/36796) The dict merge order matters and ma... — committed to ptitdoc/salt by ptitdoc 7 years ago
- Quick reproduction of https://github.com/saltstack/salt/issues/36796 — committed to lastmikoi/saltstack-bug-36796 by deleted user 6 years ago
- Quick reproduction of https://github.com/saltstack/salt/issues/36796 — committed to lastmikoi/saltstack-bug-36796 by lastmikoi 6 years ago
- ssh-client: fix merge order of options in run_wfunc (fix usage of mine.get in salt-ssh pillar) This commit fixe a long standing issue: https://github.com/saltstack/salt/issues/36796 A first attempt ... — committed to saltstack/salt by deleted user 6 years ago
Ok, cool I am able to replicate this.
As a side not, you can use
{{grains.get('os')}}
and it will work, that just uses thegrains
dictionary that is loaded into the renderer, instead of using using the grains.get salt module.@saltstack/team-ssh does anyone have an idea of why this might be happening?
Initially i thought it might have been because mine.get was in the wrappers, but grains is also in there.
Thanks, Daniel