我正在尝试构建一个reactor sls文件,该文件在事件发生时开始运行。
sls文件的内容应为以下cli命令:
sudo salt minion git.add /srv/salt .
sudo salt minion git.commit /srv/salt test
sudo salt minion git.push /srv/salt origin master identity=/home/autogit/.ssh/id_rsa如果我运行由反应堆触发的代码。我得到以下错误消息。
[DEBUG ] Reactor is populating module client cache
[ERROR ] An un-handled exception from the multiprocessing process 'Reactor-9:1' was caught:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/utils/process.py", line 765, in _run
return self._original_run()
File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 271, in run
self.call_reactions(chunks)
File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 228, in call_reactions
self.wrap.run(chunk)
File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 330, in run
self.populate_client_cache(low)
File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 324, in populate_client_cache
self.reaction_class[reaction_type](self.opts['conf_file'])
KeyError: u'module'
[CRITICAL] Engine 'reactor' could not be started!我尝试过不同的语法(旧风格和新风格),但找不到问题所在。总是得到一个模块:u‘KeyError’或u‘’git‘。
我还尝试使用runner函数在主服务器上本地运行它。
git pull:
module.run:
- git.pull:
- cwd: /srv/salt
- remote: git@git.xyz.com:user/sbt.git
- identity: /home/autogit/.ssh/id_rsa
- git.add:
- cwd: /srv/salt
- filename: .
- git.commit:
- cwd: /srv/salt
- remote: git@git.xyz.com:user/sbt.git
- git.push:
- cwd: /srv/salt
- remote: git@git.xyz.com:user/sbt.git
- identity: /home/autogit/.ssh/id_rsa
salt --versions-report
Salt Version:
Salt: 2019.2.0
Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: 2.6.1
docker-py: Not Installed
gitdb: 2.0.3
gitpython: 2.1.8
ioflo: Not Installed
Jinja2: 2.10
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.7
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
python-gnupg: 0.4.1
PyYAML: 3.12
PyZMQ: 16.0.2
RAET: Not Installed
smmap: 2.0.3
timelib: Not Installed
Tornado: 4.5.3
ZMQ: 4.2.5
System Versions:
dist: Ubuntu 18.04 bionic
locale: UTF-8
machine: x86_64
release: 4.15.0-46-generic
system: Linux
version: Ubuntu 18.04 bionic由于我对Salt还很陌生,希望您能给我一个提示,我哪里做错了:
发布于 2019-08-17 18:39:04
您没有提供主配置。
module.run混淆:添加您的设置(minion,也许是掌握,因为我不知道您的用例)use_superseded:
- module.run这将支持您的语法,有关此内容的更多文档请单击此处:https://docs.saltstack.com/en/latest/ref/states/all/salt.states.module.html#salt.states.module.run
通常:您是从只允许状态模块的地方执行执行模块的(术语模块在salt中被过度使用了……)
您还可以查看我不久前编写的关于事件和反应堆的文档:https://github.com/kiemlicz/util/wiki/Salt-Events-and-Reactor
假设已经在主配置中配置了事件到sls文件的匹配,您提供的sls:
git pull:
module.run:
- git.pull:
- cwd: /srv/salt
- remote: git@git.xyz.com:user/
...不会起作用。
请注意,反应发生在盐主上,因此反应sls文件需要提供反应类型(本地、流道等)。因为它不再是“一个跟班”,而可能是成群的跟班!
首先创建运行者反应类型(它委托给一些编排sls文件,它将包含用(我认为)salt.function 包装的逻辑)
请参考前面提到的github链接,链接到我解释Reactor的尝试。
也可以参考官方文档:https://docs.saltstack.com/en/latest/topics/reactor/index.html
https://stackoverflow.com/questions/57409497
复制相似问题