WoJ
WoJ

Reputation: 29987

How to trigger an action upon change of state?

I am testing salt as a management system, using ansible so far.

How can I trigger an action (specifically, a service reload) when a state has changed?

In Ansible this is done via notify but browsing salt documentation I cannot find anything similar.

To set an example, how the following scenario would work in salt: check a git repo (= create it if not existing or pull from it otherwise) and if it has changed, reload a service? The Ansible equivalent is

- 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

Upvotes: 0

Views: 751

Answers (1)

lakier
lakier

Reputation: 580

Your example:

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

When there will be change in repo (clone for the first time, update etc.) the state will be marked as "having changes" thus the dependent states - service.running in this case - will require changes, for service it means to restart

What you are asking is covered in salt quickstart

Upvotes: 1

Related Questions