Author statement
This document explains in detail SLS file, the name and meaning of each section, and the data structure of the data in the SLS process.
I just SaltStack beginners, if you have the wrong place text, please let us know.
In the learning process, I did some experiments, made a lot of wrong, accumulated some experience in running SaltStack also have a certain understanding, if you have any questions, or do not understand the place, welcome message exchange!
Salt State Tree
Top file
Salt State entry file system, which defines the environment minion in which SLS module loaded.
State tree
File_roots stored in the file directory of a series of SLS. SLS module using a form of organized State tree.
Include statement
Include statement
A list, whose elements are to be references to other SLS SLS module of this document. It can only be used in the top highstate structure.
Example:
include:
- edit.vim
- http.server
Module reference
Module reference
SLS module name, the file structure on the Salt master's name. Named
edit.vim
module pointsalt://edit/vim.sls
.
ID statement
ID statement
Highstate define a separate data segment. In highstate dict ID as a key, the corresponding value is another dict state declaration contains the declarations and requisit.
In the top layer with or extend highstate structure declaration.
ID must be unique in the entire State tree. If you use the same ID twice, only the first match to take effect, all other declarations of the same name ID is ignored.
Extend statement
Extend statement
SLS expansion module name declaration is referenced. Statement also extend a dict, which key ID must be defined in the referenced module SLS.
It can only be used in the top highstate structure.
When you need to add or modify another state declare SLS defined in the file, Extend statement it is very useful. The following code from mywebsite.sls file, which extend and include the apache.sls module (apache monitored object increases), so that when the automatic restart Apache service profile mywebsite changed.
include:
- apache
extend:
apache:
service:
- watch:
- file: mywebsite
mywebsite:
file:
- managed
State Statement
State Statement
A list, comprising at least a string defined function declaration, dict 0 Arg or more function declarations.
There are some optional members, such as covering part of the name (name and names statement), requistie statement.
ID can only be used in a statement.
Requisite statement
Requisite statement
A list, whose members are requisite references.
Generating a dependency tree for operation. Salt states designed to perform, require sequential or watch other Salt state may be adjusted according to the determined order of execution.
As used in the assembly state list a statement, or used as a key in the ID claims.
Requisite quote
Requisite quote
Only one key of dict. key is the name of state declared cited, value is the name of the referenced statement ID. It can only be used as a member of the requisite declaration.
Function Statement
Function Statement
state of the function to be performed. A state statement can only have one function declaration.
The following example, state declared a state call pkg module installed modules function.
httpd:
pkg.installed
The acronym may be declared as inline function (in the above example is), such that the data structure using the full wording more clearly:
httpd:
pkg:
- installed
Note that two consecutive short form is invalid, for the avoidance of doubt, we recommend that all use the full wording.
INVALID:
httpd:
pkg.installed
service.running
VALID:
httpd:
pkg:
- installed
service:
- running
It can only be used as a member state declaration.
Function arg statement
Function arg statement
Only one key of dict, passed as a parameter to a function declaration, which value is a valid Python type. Its type must meet the function needs. In a statement by function.
The following example, state statement file, function declaration is managed, user, group, and mode parameters are passed to the managed:
/etc/http/conf/http.conf:
file.managed:
- user: root
- group: root
- mode: 644
Name Statement
Name Statement
Cover name parameter state declaration. The default value of the name parameter is the ID statement. name dictionary is always a single key, the value type is string.
In some scenarios, modify the default name parameter is useful. For example, avoid ID conflicts. The following two examples state can not be used /etc/motd
as ID:
motd_perms:
file.managed:
- name: /etc/motd
- mode: 644
motd_quote:
file.append:
- name: /etc/motd
- text: "Of all smells, bread; of all tastes, salt."
Another scenario is declared using the name, ID statement is very long, but also need to reference this ID in multiple times. In the following example, the use mywebsite
ratio /etc/apache2/sites-available/mywebsite.com
is more convenient:
mywebsite:
file.managed:
- name: /etc/apache2/sites-available/mywebsite.com
- source: salt://mywebsite.com
a2ensite mywebsite.com:
cmd.wait:
- unless: test -L /etc/apache2/sites-enabled/mywebsite.com
- watch:
- file: mywebsite
apache2:
service:
- running
- watch:
- file: mywebsite
Names statement
Names statement
The state declared a state declaration extended to multiple different names.
See the examples below:
python-pkgs:
pkg.installed:
- names:
- python-django
- python-crypto
- python-yaml
Lowstate the converted result is:
python-django:
pkg.installed
python-crypto:
pkg.installed
python-yaml:
pkg.installed
Complete Example
The following YAML is a complete example, which part of the name using hightstate component name.
<Include Declaration>:
- <Module Reference>
- <Module Reference>
<Extend Declaration>:
<ID Declaration>:
[<overrides>]
# standard declaration
<ID Declaration>:
<State Declaration>:
- <Function>
- <Function Arg>
- <Function Arg>
- <Function Arg>
- <Name>: <name>
- <Requisite Declaration>:
- <Requisite Reference>
- <Requisite Reference>
# inline function and names
<ID Declaration>:
<State Declaration>.<Function>:
- <Function Arg>
- <Function Arg>
- <Function Arg>
- <Names>:
- <name>
- <name>
- <name>
- <Requisite Declaration>:
- <Requisite Reference>
- <Requisite Reference>
# multiple states for single id
<ID Declaration>:
<State Declaration>:
- <Function>
- <Function Arg>
- <Name>: <name>
- <Requisite Declaration>:
- <Requisite Reference>
<State Declaration>:
- <Function>
- <Function Arg>
- <Names>:
- <name>
- <name>
- <Requisite Declaration>:
- <Requisite Reference>