How to Use the require and watch syntax in saltstack

Source: Internet
Author: User
Tags saltstack

Requisites

Require

Require_in

Watch

Watch_in

Conclusion)

Many powerful options are supported in the saltstack configuration relational system. Whether it is a simple installation of software packages or the use of templates and conditional statements. saltstack states can gradually become very complex from small to small. Fortunately, saltstack provides a method for solving the dependency between States. This section describes how to use require, require_in, watch, and watch_in.


Requisites

In the world of saltstack, there are two types of requisites (the Translator's note: This word does not find a proper Chinese translation and the original English word is used for the time being): requisites and "requisite_ins ". These requisites are ctional, used to specify that "I depend on something" or "something depends on me"


Require

The following example uses the require Syntax:


VIM:

PKG. Installed


/Etc/vimrc:

File. managed:

-Source: salt: // edit/vimrc

-Require:

-PKG: Vim

In this example, the/etc/vimrc file is not placed (managed) until the vim package is installed.


Require_in

The following is the same example, but require_in is used this time:


VIM:

PKG. installed:

-Require_in:

-File:/etc/vimrc


/Etc/vimrc:

File. managed:

-Source: salt: // edit/vimrc

In this example, the effect is the same. In vim, the/etc/vimrc depends on me.


At the end, a dependency map is created and executed in a finite (finite) and foreseeable (predictable) Order.


Watch

The following uses the watch syntax as an example. In this example, the running ntpd service will pay attention to/etc/NTP. if the conf file changes, the service will be restarted.


NTPD:

Service. Running:

-Watch:

-File:/etc/NTP. conf


/Etc/NTP. conf:

File. managed:

-Source: salt: // NTP/files/NTP. conf

Watch_in

In the following example, the/etc/NTP. conf Declaration (declaring) should be watched by the ntpd service


NTPD:

Service. Running


/Etc/NTP. conf:

File. managed:

-Source: salt: // NTP/files/NTP. conf

-Watch_in:

-Service: NTPD

Conclusion)

In the state rule, you can specify the dependency between States through powerful require, require_in, watch, and watch_in. whether a service should watch a file change, or make sure that the software package has been installed before a service runs, they can be used to specify the logic execution sequence of state.


This article is from the "davideylee" blog and will not be reposted!

How to Use the require and watch syntax in saltstack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.