Chapter 9. Salt Reactor

The reactor is an engine module that listens to Salt’s event bus and matches incoming event tags with commands that should be run in response. It is useful to automatically trigger actions in immediate response to things happening across an infrastructure.

For example, a file changed event from the inotify beacon could trigger a state run to restore the correct version of that file, and a custom event pattern could post info/warning/error notifications to a Slack or IRC channel.

Note

The reactor is an engine module (see Chapter 8) and uses the event bus (Chapter 6) so it will be helpful to read those chapters before this one. In addition, the reactor is often used to respond to events generated by beacon (Chapter 7) or engine modules.

Getting Started

Salt’s reactor adheres to the workflow: match an event tag; invoke a function. It is best suited to invoking simple actions, as we’ll see in “Best Practices”. The configuration is placed in the master config file and so adding and removing a reaction configuration will require restarting the salt-master daemon.

To start we will create a reaction that listens for an event and then initiates a highstate run on that minion (Example 6-5). The end result is the same as with the startup_states setting except that the master will trigger the state run rather than the minion. Add the code shown in Example 9-1 to your master config.

Example 9-1. /etc/salt/master
reactor:
  - 'napalm/syslog/*/NTP_SERVER_UNREACHABLE/*' ...

Get Network Automation at Scale now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.