×
REACTOR FOR EVENT DRIVEN INFRASTRUCTURE SALTSTACK
Automation Blog

REACTOR FOR EVENT DRIVEN INFRASTRUCTURE SALTSTACK

(This post is continuation of ENABLING BEACONS IN SALTSTACK.)

In this post we are going to create the reactor for event driven infrastructure saltstack, Salt’s Reactor system gives Salt the ability to trigger actions in response to an event. It is a simple interface to watching Salt’s event bus for event tags that match a given pattern and then running one or more commands in response.

Description: Ubuntu 16.04.2 LTS

Saltmaster: 192.168.232.70

host1: 192.168.232.71

host2: 192.168.232.72

Reactor config for Service(Nginx and Diskusage):

# cat /etc/salt/master.d/reactor.conf

reactor:

– ‘salt/beacon/*/service/’:

– /srv/reactor/nginx-mon.sls

reactor for event driven infrastructure saltstack

Reactor config-handler:

# cat /srv/reactor/nginx-mon.sls

{% if data[‘id’] %}

web_state_run:

local.state.apply:

– tgt: {{ data[‘id’] }}

– arg:

– webserver.nginx_up

{% endif %}

reactor for event driven infrastructure saltstack

# cat /srv/reactor/disk-cleanup.sls

{% if data[‘id’] %}

cleanup_tmp_dir:

local.state.apply:

– tgt: {{ data[‘id’] }}

– arg:

– disk-cleanup

{% endif %}

reactor for event driven infrastructure saltstack

Reactor execution state file:

# cat /srv/salt/webserver/nginx_up.sls

make_nginx_online:

service.running:

– name: nginx

reactor for event driven infrastructure saltstack

# cat /srv/salt/disk-cleanup.sls

clean_tmp_directory:

file.absent:

– name: /tmp/bigfile2

reactor for event driven infrastructure saltstack

Let us restart the salt-master service.

on salt-master:

# salt-run state.event pretty=True

(or)

We can see even more information by starting the salt-master into debug mode, lets check the below command.

# salt-master -l debug

(use killall -9 salt-master if you unable to start the salt-master in debug-mode and with error like service already listening)

On the event bus:

Reactor check Nginx service:

reactor for event driven infrastructure saltstack

reactor for event driven infrastructure saltstack

Reactor check disk usage:

reactor for event driven infrastructure saltstack

– (run the command: ‘dd if=/dev/zero of=/tmp/bigfile2 bs=1M count=2000’ on minion to increase the diskspace)

reactor for event driven infrastructure saltstack

The disk space exceeds the limit now, lets see the reactor

reactor for event driven infrastructure saltstack

reactor for event driven infrastructure saltstack

Reactor check through debug-mode:

Nginx service:

We need to stop the salt-master service,

# systemctl stop salt-master

Start the salt-master in debug-mode.

# salt-master -l debug

We can see lot of debug and info messages on the screen,

reactor for event driven infrastructure saltstack

reactor for event driven infrastructure saltstack

reactor for event driven infrastructure saltstack

Disk usage:

reactor for event driven infrastructure saltstack

– (run the command: ‘dd if=/dev/zero of=/tmp/bigfile2 bs=1M count=2000’ on minion to increase the diskspace)

reactor for event driven infrastructure saltstack

The disk space exceeds the limit now, lets see the reactor

– disk-cleanup.sls contents should be based on your circumstances, no need to use the same like /tmp/bigfile2.

reactor for event driven infrastructure saltstack

clip_image025

As we already created the file bigfile2 under the /tmp, so that we have added to remove that file to make the disk usage within the limit, you can use files based on your environment or disk usage.

Video:

Thanks!!

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.