SLS for Saltstack (7)

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:-/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   later mentions   my_app:               #通过分组名去进行匹配   must be defined match:nodegroup    -  match: nodegroup    - nginx   ' Os:redhat ':          #通过grains模块去匹配, you have to define Match:grain    - match: grain     - nginx 

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

Cd/srv/salt Vim Nginx.sls

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:                   #检测下面两个配置文件, 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 the location of the Conf configuration file above the salt     - 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:       - pkg: nginx

Create files/nginx/nginx.conf, files/nginx/, below the current directory (the Salt's home directory) fastcgi.conf file, it must be your own configuration of the Nginx configuration file content, the use of salt to automate, general Nginx are familiar with, do not explain in detail here

Test installation:

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

To minion above push, general salt ' sa10-003 ' state.sls this command; Of course, you can also perform salt sa10-003 state.highstate This command will match all 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-php

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:-Pkg:nginx

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-pkg:nginx

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:-Order:1

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


SLS for Saltstack (7)

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.