如何在状态改变时触发动作?
How to trigger an action upon change of state?
我正在测试 salt
作为管理系统,到目前为止使用 ansible
。
如何在状态发生变化时触发操作(特别是服务重新加载)?
在 Ansible 中,这是通过 notify
完成的,但是浏览 salt
文档我找不到任何类似的东西。
我找到了 watch
,它反过来工作:"check something, and if it changed to this and that".
还有listen
似乎更接近我的需求(文档中提到了服务重载)但我无法将它们拼凑起来。
举个例子,以下场景在 salt
中的工作方式:检查 git
存储库(= 如果不存在则创建它,否则从中提取),如果它已更改,重新加载服务? Ansible 等价物是
- name: clone my service
git:
clone: yes
dest: /opt/myservice
repo: http://git.example.com/myservice.git
version: master
force: yes
notify:
- restart my service if needed
- name: restart my service if needed
systemd:
name: myservice
state: restarted
enabled: True
daemon_reload: yes
你的例子:
ensure my service:
git.latest:
- name: http://git.example.com/myservice.git
- target: /opt/myservice
service.running:
- watch:
- git: http://git.example.com/myservice.git
回购什么时候会有变化(第一次克隆,更新等)
该状态将被标记为 "having changes" 因此依赖状态 -
service.running
在这种情况下 - 将需要更改,因为 service
意味着重新启动
你问的内容在salt quickstart
中
我正在测试 salt
作为管理系统,到目前为止使用 ansible
。
如何在状态发生变化时触发操作(特别是服务重新加载)?
在 Ansible 中,这是通过 notify
完成的,但是浏览 salt
文档我找不到任何类似的东西。
我找到了
watch
,它反过来工作:"check something, and if it changed to this and that".还有
listen
似乎更接近我的需求(文档中提到了服务重载)但我无法将它们拼凑起来。
举个例子,以下场景在 salt
中的工作方式:检查 git
存储库(= 如果不存在则创建它,否则从中提取),如果它已更改,重新加载服务? Ansible 等价物是
- name: clone my service
git:
clone: yes
dest: /opt/myservice
repo: http://git.example.com/myservice.git
version: master
force: yes
notify:
- restart my service if needed
- name: restart my service if needed
systemd:
name: myservice
state: restarted
enabled: True
daemon_reload: yes
你的例子:
ensure my service:
git.latest:
- name: http://git.example.com/myservice.git
- target: /opt/myservice
service.running:
- watch:
- git: http://git.example.com/myservice.git
回购什么时候会有变化(第一次克隆,更新等)
该状态将被标记为 "having changes" 因此依赖状态 -
service.running
在这种情况下 - 将需要更改,因为 service
意味着重新启动
你问的内容在salt quickstart
中