我刚刚开始将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.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:必需的错误。
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谢谢你试图回答我的问题!
发布于 2015-06-25 09:44:17
watch: file:必需不是指文件系统上的文件更改,而是指在文件系统执行过程中所定义的状态的更改。
在这种情况下,您必须观看state:
- watch:
- cmd: "/etc/postfix/canonical.db"如果要对*.db文件的外部更改作出反应,则必须使用另一种方式。你可以看看反应堆系统:https://docs.saltstack.com/en/latest/topics/reactor/index.html。我不太了解它,但我认为它可以用于对文件系统的更改作出反应。
https://serverfault.com/questions/701512
复制相似问题