SaltStack:未找到监视的必备条件

pep*_*uan 2 saltstack

我刚刚开始将 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
Run Code Online (Sandbox Code Playgroud)

基本上,我想在/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:
Run Code Online (Sandbox Code Playgroud)

其他州运行完美。

我是 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
Run Code Online (Sandbox Code Playgroud)

感谢您尝试回答我的问题!

Chr*_*uet 5

必要条件watch: file:不是指文件系统上的文件更改,而是指在执行期间定义的状态发生更改。

在这种情况下,您必须观看state

- watch:
  - cmd: "/etc/postfix/canonical.db"
Run Code Online (Sandbox Code Playgroud)

如果您想对文件的外部更改做出反应*.db,则必须使用其他方法。您可以查看 Reactor 系统:https://docs.saltstack.com/en/latest/topics/reactor/index.html。我对此了解不多,但我认为它可以用于对文件系统更改做出反应。