我刚开始部署SaltStack到我的服务器。 所以,我有以下文件/srv/salt/postfix/init.sls :
# Ensure postfix installed and set to autostart on boot postfix: pkg.installed: [] service.running: - require: - pkg: postfix - enable: True # Restart on change to main.cf or any of the *.db files postfix.restart: service.running: - require: - pkg: postfix - name: postfix - watch: - file: "/etc/postfix/main.cf" - file: "/etc/postfix/*.db" # Without this, first watch above fails /etc/postfix/main.cf: file.exists: [] /etc/postfix/canonical: file.managed: - require: - pkg: postfix - source: salt://postfix/canonical - template: jinja /etc/postfix/canonical.db: cmd.wait: - name: /usr/sbin/postmap /etc/postfix/canonical - watch: - file: /etc/postfix/canonical
基本上,我想在/etc/postfix/canonical.db文件更改时重新启动Postfix。
但是每当我运行这个状态,我总是得到postfix.restart状态的错误:
ID: postfix.restart Function: service.running Name: postfix Result: False Comment: The following requisites were not found: watch: file: /etc/postfix/*.db Started: Duration: Changes:
其他州完美运行。
我是SaltStack的初学者,所以请帮助我找出问题出在哪里,如果我真的写了一个“正确”的SaltStack公式。
谢谢!
PS: salt --version返回salt 2015.5.0 (Lithium) ,我在Ubuntu上。
PPS:从*.db更改为canonical.db不会更改结果:该watch:上的错误仍然存在watch:必需。
PPPS:我最初将cmd.wait节放在/etc/postfix/canonical作业下,并把它分成了一个不同的工作,因为我认为这个错误是由于watch:找不到工作。
我已经放弃了原来的策略,而是采用了基于GNU make的策略。
参考: http : //www.unixwiz.net/techtips/postfix-makefiles.html
所以init.sls现在看起来像这样:
postfix: pkg.installed: [] service.running: - require: - pkg: postfix - enable: True make: pkg.installed: [] /etc/postfix/Makefile: file.managed: - require: - pkg: postfix - pkg: make - source: salt://postfix/Makefile refresh_db: cmd.run: - require: - pkg: postfix - pkg: make - name: make - cwd: /etc/postfix - order: last ## IMPORTANT! This will force this particular job to run at the very last /etc/postfix/canonical: file.managed: - require: - pkg: postfix - source: salt://postfix/canonical - template: jinja
谢谢你试图回答我的问题!
watch: file: requisite并不是指文件系统上的文件更改,而是指执行期间定义状态的更改。
在这种情况下,你必须观察state :
- watch: - cmd: "/etc/postfix/canonical.db"
如果您想要对*.db文件进行外部更改,则必须使用其他方法。 你可以看一下反应堆系统: https : //docs.saltstack.com/en/latest/topics/reactor/index.html 。 我不太了解它,但我认为它可以用来对文件系统的变化作出反应。