EXAMPLE FOR WATCH REQUISITES IN SALTSTACK:

WATCH REQUISITES IN SALTSTACK

WATCH REQUISITES IN SALTSTACK:

We are going to see the simple example for watch requisites in saltstack here, The watch statements are used to add additional behavior when there are changes in other states

A good example of using watch is with a service.running state.

When a service watches a state, then the service is reloaded/restarted when the watched state changes, in addition to Salt ensuring that the service is running. To verify the minion is responding,

salt ‘first-minion’ test.ping

watch requisites in saltstack

Our state file looks like,

# cat httpd_watch.sls

  apache_service:

   service.running:

    – name: httpd.service

    – require:

     – pkg: apache_service

    – watch:

     – file: apache_service

     – file: modify_content

  pkg.installed:

   – name: httpd

  file.managed:

   – source: salt://rnd1.conf

   – name: /etc/httpd/conf.d/rnd1.conf

   – require:

    – pkg: apache_service

  modify_content:

   file.managed:

    – source: salt://index.html

    – name: /home/rnd1/index.html

    – user: apache

    – group: apache

    – mode: 644

   – require:

    – pkg: apache_service

watch requisites in saltstack

watched state files:

rnd1.conf file contains:

<VirtualHost 192.168.233.21:8081>

#    ServerAdmin webmaster@dummy-host.example.com

    DocumentRoot /home/rnd1

    DirectoryIndex index.html

#    ServerName server1.times.com

#    ErrorLog logs/dummy-host.example.com-error_log

#    CustomLog logs/dummy-host.example.com-access_log common

<Directory />

    AllowOverride none

    Require all denied

</Directory>

<Directory /home/rnd1>

    AllowOverride none

    Require all granted

</Directory>

</VirtualHost>

 

watch requisites in saltstack

Index.html file contains:

<h1> My new page </h1>

watch requisites in saltstack

watch requisites,

apache_service:

 service.running:

  – name: httpd.service

  – require:

    – pkg: apache_service

  – watch:

    – file: apache_service

    – file: modify_content

In the state file we have placed two states under the watch requisites, As per the state file if any changes on the apache_service or modify_content state then the apache service will be restarted / reloaded.

  • We have already installed apache in the salt-minion and done few configurations like,
  • Added Listen server_IP:8081
  • Allowed 8081 in firewall

Let us trigger the state file on the target by,

salt ‘first-minion’ state.sls httpd_watch

watch requisites in saltstack

watch requisites in saltstack

Apache service has been restarted since the apache_service and modify_content states were changed.

Let us check the web page:

watch requisites in saltstack

When we execute the state file without any modification on watched state then the result looks like,

watch requisites in saltstack

Let us modify the watched states:

salt ‘first-minion’ state.sls httpd_watch

Modification on the rnd1.conf file:

watch requisites in saltstack

Modification on the index.html file:

watch requisites in saltstack

Result on the web page:

watch requisites in saltstack

As we already mentioned if there is no changes on the watched states then the service will not restarted instead of showing the service’s status.

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn
More Interested Related Posts
zfs pool usage

ZFS Pool and Dataset Usage

ZFS Pool and Dataset Usage   I am back with another blog to provide the useful script to the Freebsd users to determine the zpool

Assistanz Networks

Installing Zabbix Agent in FreeBSD 12.0

Zabbix Agent Installation and Configuration Guide on FreeBSD 12.0   Zabbix is an open-source monitoring software tool for diverse IT components, including networks, servers, virtual

DirectAdmin Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk
$ 99 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • NDA & SLA
  • SLA Review Meetings
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation
  •  

Platinum Support

24/7 Proactive Support
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Support

$ 30 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response Time
  • 4 Hours Resolution time for the Possible Issues
  • Security and Performance Optimization
  • React to Customers queries
  • Simple SignUp Process
  • Instant Account Activation
  • No Third party application support
  • No Migration and End User Support

Cpanel Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk

$ 99 Monthly / Server
  • 24/7 End User White Label Support
  • Unlimited Number of Tickets
  • Chat Support for Admin
  • Separate Account Manager
  • Guaranteed SLA
  • Weekly Status Reports
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation

Platinum Support

24/7 Proactive Server Management
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Server Management

$ 29 Monthly / Server
  • Unlimited Admin Tasks
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response time
  • 4 hours Response time for possible issues
  • Security and Performance Optimization
  • React to Customers queries
  • No Third party application support
  • No Migration and End User Support

Cpanel Server Management Plans

Premium Support

24/7 End User Support from your Helpdesk

$ 99 Monthly / Server
  • 24/7 End User White Label Support
  • Unlimited Number of Tickets
  • Chat Support for Admin
  • Separate Account Manager
  • Guaranteed SLA
  • Weekly Status Reports
  • FREE Consultancy Services
  • Simple SignUp Process
  • Instant Account Activation

Platinum Support

24/7 Proactive Server Management
$ 49 Monthly / Server
  • Unlimited Support Plan
  • 24/7 Emergency Phone
  • Chat Support for Admin
  • Separate Account Manager
  • Advance Proactive Monitoring
  • Guaranteed SLA
  • SLA Review Meetings
  • 3rd Party Application Support
  • FREE Consultancy Services
  • Server Migration Support
  • Weekly Status Report
  • No End User Support
Popular

Unlimited Support

24/7 Server Management

$ 29 Monthly / Server
  • Unlimited Admin Tasks
  • 24/7 Support
  • Basic Monitoring
  • 30 Minutes Response time
  • 4 hours Response time for possible issues
  • Security and Performance Optimization
  • React to Customers queries
  • No Third party application support
  • No Migration and End User Support