我正在使用SaltStack,并为谷物上的小兵们提供支柱文件。
当我在minions CLI上运行mine.get命令时,它运行正常:
salt-call mine.get 'role:production-server' network.ip_addrs grain
返回主机及其IP的列表。
但是,在同一个minion的jinja模板中使用相同的命令会导致错误:
{% for host, ip in salt['mine.get']('role:production-server', 'network.ip_addrs', expr_form='grain').items() %}
local:
Data failed to compile:
----------
Pillar failed to render with the following messages:
----------
Rendering SLS 'role_settings.staging-server' failed, render error:
Jinja error: 'master_uri'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 265, in render_jinja_tmpl
output = template.render(**unicode_context)
File "/usr/lib/python2.7/dist-packages/jinja2/environment.py", line 894, in render
return self.environment.handle_exception(exc_info, True)
File "<template>", line 25, in top-level template code
File "/usr/lib/python2.7/dist-packages/salt/modules/mine.py", line 182, in get
auth = _auth()
File "/usr/lib/python2.7/dist-packages/salt/modules/mine.py", line 24, in _auth
__context__['auth'] = salt.crypt.SAuth(__opts__)
File "/usr/lib/python2.7/dist-packages/salt/crypt.py", line 498, in __init__
self.crypticle = self.__authenticate()
File "/usr/lib/python2.7/dist-packages/salt/crypt.py", line 510, in __authenticate
self.opts.get('_safe_auth', True)
File "/usr/lib/python2.7/dist-packages/salt/crypt.py", line 341, in sign_in
if self.opts['master_ip'] not in self.opts['master_uri']:
KeyError: 'master_uri'
我对导致这种情况的原因感到茫然,因为它在命令行中工作正常,这似乎排除了与盐主管等沟通的问题。
答案 0 :(得分:1)
我知道这是一个老帖子但是......
您似乎正在调用自定义Python模块来访问您的支柱文件中的矿。
这在公式的上下文中很好,但默认情况下不支持柱数据,因为自定义模块位于minion上但是支柱数据是在主机上编译的。
为了允许主机访问minion模块,你需要在Salt master配置中添加这样的东西:
module_dirs:
- /var/cache/salt/minion/extmods
添加完毕后,您需要重新启动Salt master:
sudo service salt-master restart
注意:我怀疑上述设置仅在您安装了自定义模块的Salt Master上安装并配置了Salt Minion时才有效。
有关详细信息,请参阅Salt docs:https://docs.saltstack.com/en/latest/ref/configuration/master.html#module-dirs