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