The use of Saltstack/salt's State.sls

Source: Internet
Author: User
Tags saltstack

The SLS (representing the salt state file) is the core of the salt State system. SLS describes the target state of the system, which is composed of simple data formats. This is often referred to as configuration management first, the home directory of the salt is defined on the master, and the default is under/srv/salt/, Vim/etc/salt/master:

File_roots:   Base:     -/srv/salt   Dev:    

Then, create the Top.sls file under/srv/salt (if any, don't create it, edit it directly) Vim Top.sls

Base  

Top.sls default from the base tag to start parsing execution, the next level is the target of the operation, you can use the regular, grain module, or group name, to match, and then the next level is to execute the state file

Base:  ' * ':               #通过正则去匹配所有minion    -nginx          #这里都是我自己写的state. SLS Module Name here can be ignored the following will refer to  My_app:             # Match must be defined by grouping name Match:nodegroup    -Match:nodegroup    -nginx  ' os:redhat ':        #通过grains模块去匹配, match must be defined: Grain    -Match:grain    

The whole TOP.SLS approximate format is this appearance, after writing Top.sls, write State.sls file;

nginx.sls content:

 nginx:pkg: #定义使用 (pkg state module)-Installed #安装nginx (yum installation) Service.running: #保持服务是启动状态 -Enable:true-reload:true-require:-File:/etc/init.d/nginx-watch: #检测下面两个配置文件,  There is a change, immediately execute the above/etc/init.d/nginx command reload operation-file:/etc/nginx/nginx.conf-file:/etc/nginx/fastcgi.conf-pkg: nginx/etc/nginx/nginx.conf: #绝对路径 file.managed:-source:salt://files/nginx/nginx.conf #nginx. conf configuration file above the salt Location-User:root-mode:644-template:jinja #salt使用jinja模块-require:-pkg:nginx/etc/nginx/fastcgi . Conf:file.managed:-Source:salt://files/nginx/fastcgi.conf-user:root-mode:644-require:-PK G:nginx 

Create the files/nginx/nginx.conf, files/nginx/fastcgi.conf file under the current directory (the Salt's home directory), which must be the contents of the Nginx configuration file of your own configuration, and use salt for automation. General Nginx are quite familiar, here do not explain in detail

Test installation:

[email protected] salt # Salt ' sa10-003 ' State.sls nginx test=true The output information is omitted here summary------------succeeded:8failed:    0------------Total:     

When pushing the minion above, the general Salt ' sa10-003 ' state.sls this command; Of course, you can also perform salt sa10-003 state.highstate This command will match all of the STATE.SLS modules by default. where test=true refers to a test installation, that is, no actual operation, just to see the test results.

List of logical relationships for state:

Include: Contains a file such as my new My_webserver.sls file, you can inherit the Nginx and PHP related module configuration, without having to rewrite

[email protected] Salt # Cat MY_WEBSERVER.SLS include:  -Nginx  

Match: Modulo a module, such as the Match:grain Match:nodegroup require that was previously defined TOP.SLS: Depending on a state, run the dependent state before running this state, and the dependency can have multiple For example, in the Nginx module, the relevant configuration must first rely on Nginx installation

-Require:  

Watch: Run this module when a state changes, the configuration in the text, the relevant file changes, immediately take the appropriate action

-Watch:  -file:/etc/nginx/nginx.conf  -File:/etc/nginx/fastcgi.conf  

Order: The priority is lower than require and watch, and the state with order specifies a higher priority than no order, and if multiple services, or other dependencies, are installed within a state module, you can use

Nginx:  pkg.installed:    

To make the last run of a state, you can use

The use of Saltstack/salt's State.sls

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.