Salt's mine.get command works on CLI but not in a jinja template
我用的是盐堆,还有跟谷物相匹配的奴才的支柱文件。
当我在minions cli上运行mine.get命令时,它工作正常:
但是,在同一个迷你上使用jinja模板中的相同命令会导致错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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' |
我对造成这种情况的原因一无所知,因为它在命令行中运行良好,这似乎排除了与salt master通信等问题。
我知道这是一篇旧文章,但是…
您似乎正在调用自定义python模块以访问支柱文件中的挖掘。
在公式上下文中这很好,但默认情况下不使用支柱数据,因为自定义模块在迷你上,而支柱数据在主控上编译。若要允许主控访问迷你模块,您需要添加一些内容您的盐主机配置如下:
1 2 | module_dirs: - /var/cache/salt/minion/extmods |
添加后,需要重新启动盐主机:
1 | sudo service salt-master restart |
注意:我怀疑只有在安装了自定义模块的salt master上安装并配置了salt minion时,上述设置才有效。有关更多信息,请参阅以下salt文档:https://docs.saltstack.com/en/latest/ref/configuration/master.html module dirs