In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to understand the definition of Salt Highstate data structure, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
The editor will introduce in detail the name and meaning of each part of the SLS file, as well as the data structure after data processing in SLS.
Salt State Tree
Top file
The entry file for the Salt State system, which defines which environment minion is in and which SLS modules are loaded.
State tree
A series of SLS files stored in the file_roots directory. Organize the State tree in the form of a SLS module.
Include statement
Include statement
A list whose elements are other SLS modules to be referenced into this SLS file. Can only be used at the top level of the highstate structure.
Example:
Include:-edit.vim-http.serverModule reference
Module reference
The name of the SLS module, named after the file structure on Salt master. A module named edit.vim points to salt://edit/vim.sls.
ID statement
ID statement
Define a separate highstate segment. ID acts as a key in highstate dict, and its corresponding value is another dict that contains a state declaration and a requisit declaration.
Used at the top of the highstate structure or at the next level of the extend declaration.
ID must be unique throughout the State tree. If the same ID is used twice, only the first match takes effect, and all other ID declarations with the same name are ignored.
Extend statement
Extend statement
Extend the name declaration in the referenced SLS module. The extend declaration is also a dict, and its key must be the ID defined in the referenced SLS module.
Can only be used at the top level of the highstate structure.
Extend declarations are useful when you need to add or modify state declarations defined in another SLS file. The following code comes from the mywebsite.sls file, where include and extend the apache.sls module (with the addition of apache monitoring objects), so that the Apache service automatically restarts when the configuration file mywebsite changes.
Include:-apacheextend: apache: service:-watch:-file: mywebsitemywebsite: file:-managedState declaration
State statement
A list that contains at least one dict of string,0 or more function declarations that define function arg declarations.
There are also some optional members, such as name overrides (name and names declarations) and requistie declarations.
Can only be used at the next level of the ID declaration.
Requisite statement
Requisite statement
A list whose member is a requisite reference.
Used to generate action dependency trees. Salt states is designed to be executed in a determined order, and require or other Salt state of watch can adjust the order of execution.
Used as a list component at the next level of the state declaration, or as a key at the next level of the ID declaration.
Requisite reference
Requisite reference
There is only one dict for key. Key is the name of the referenced state declaration, and value is the name of the referenced ID declaration. Can only be used as a member of a requisite declaration.
Function statement
Function statement
The function to be executed in state. There can be only one function declaration in 1 state declaration.
In the following example, the state declaration invokes the installed function in the state module pkg module.
Httpd: pkg.installed
You can declare function in an inline abbreviation (as in the example above), using full writing to make the data structure clearer:
Httpd: pkg:-installed
It should be noted that the two consecutive abbreviations are invalid. In order to avoid confusion, it is recommended that all of them be written in a complete way.
INVALID:
Httpd: pkg.installed service.running
VALID:
Httpd: pkg:-installed service:-running
Can only be used as a member of a state declaration.
Function arg statement
Function arg statement
There is only one dict of key, passed as a parameter to the function declaration, whose value is a valid Python type. Its type must meet the needs of function. Used at the next level of the function declaration.
In the following example, the state declaration is the file,function declaration that managed,user, group, and mode are parameters passed to managed:
/ etc/http/conf/http.conf: file.managed:-user: root-group: root-mode: 644Name statement
Name statement
Override the name parameter in the state declaration. The default value of the name parameter is the ID declaration. Name is always a single key dictionary with a value type of string.
In some scenarios, it is useful to modify the default name parameters. For example, ID conflicts can be avoided. The two state in the following example cannot use / etc/motd as the ID at the same time:
Motd_perms: file.managed:-name: / etc/motd-mode: 644motd_quote: file.append:-name: / etc/motd-text: "Of all smells, bread; of all tastes, salt."
Another scenario where the name declaration is used is that the ID declaration is very long and the ID needs to be referenced multiple times. In the following example, using mywebsite is much more convenient than / etc/apache2/sites-available/mywebsite.com:
Mywebsite: file.managed:-name: / etc/apache2/sites-available/mywebsite.com-source: salt://mywebsite.coma2ensite mywebsite.com: cmd.wait:-unless: test-L / etc/apache2/sites-enabled/mywebsite.com-watch:-file: mywebsiteapache2: service:-running-watch:-file: mywebsiteNames statement
Names statement
Extend 1 state declaration to multiple state declarations with different names.
Look at the following example:
Python-pkgs: pkg.installed:-names:-python-django-python-crypto-python-yaml
The result of conversion to lowstate is:
Python-django: pkg.installedpython-crypto: pkg.installedpython-yaml: pkg.installed complete example
The following YAML is a complete example, where the name part uses the hightstate component name.
:--:: [] # standard declaration::-- # inline function and names:.:-- # multiple states for single id: : -:-after reading the above Do you have any further understanding of how to understand the definition of Salt Highstate data structures? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.