如何指示 saltstack 重新加载 firewalld?

how to instruct saltstack to reload firewalld?

我正在尝试通过 saltstack 状态文件(在 Centos7 上)配置 firewalld。我可以将服务很好地添加到永久配置中,但这确实进入了 'permanent' 配置,而不是 运行 配置。因此,要么需要重新加载,要么(可选性较低)也将相同的服务添加到 运行 配置。

我用来添加服务的:

public: firewalld.present: - name: public - services: - http 这行得通,但只是为了永久。

我试过添加 "watch",但这根本行不通:

firewalld: service.running: - watch: - file: /etc/firewalld/zones/public.xml 错误是:

Comment: The following requisites were not found: watch: file: /etc/firewalld/zones/public.xml

那么,可以做什么呢?如何通过状态文件指示服务重新加载?

你很接近。您不能直接在文件系统上查看文件。您只能观看另一个 Salt 状态。所以你的例子看起来像这样:

public:
  firewalld.present:
    - name: public
    - services:
      - http

firewalld:
  service.running:
    - watch:
      - firewalld: public

这意味着 service.running 状态将寻找对 firewalld.present 状态的更改,如果确实发生更改,则重新启动 firewalld。

如果您想要 reload 与完全重启,这应该可行:

public:
  firewalld.present:
    - name: public
    - services:
      - http

firewalld:
  service.running:
    - reload: True
    - watch:
      - firewalld: public

这是关于服务状态的文档:https://docs.saltstack.com/en/latest/ref/states/all/salt.states.service.html