一、介绍
功能:salt基于state进行minion的状态管理。
官方介绍:
Salt offers an optional interface to manage the configuration or “state” of the Salt minions. This interface is a fully capable mechanism used to enforce the state of systems from a central manager.
The Salt state system is made to be accurate, simple, and fast. And like the rest of the Salt system, Salt states are highly modular.
二、参考文档
state 介绍文档:
http://docs.saltstack.com/ref/states/
state 模块文档:
http://docs.saltstack.com/ref/states/all/index.html
state 逻辑关系文档:
http://docs.saltstack.com/ref/states/requisites.html
http://docs.saltstack.com/ref/states/ordering.html
三、基本配置
配置结构:
$ID: $State: - $state: states
示例:
vim:
pkg:
- installed</pre>
如果是redhat系列的就安装 vim-enhanced,如果系统是Debian或者Ubuntu就安装vim-nox
四、逻辑关系
state之间还可以使用require, include, extend等关系进行关联。
require:依赖某个state,在运行此state前,先运行依赖的state,依赖可以有多个
httpd:
pkg:
- installed
file.managed:
- name: /etc/httpd/conf/httpd.conf
- source: salt://httpd/httpd.conf
- require:
- pkg: httpd</pre>
watch:在某个state变化时运行此模块
redis:
pkg:
- latest
file.managed:
- source: salt://redis/redis.conf
- name: /etc/redis.conf
- require:
- pkg: redis
service.running:
- enable: True
- watch:
- file: /etc/redis.conf
- pkg: redis</pre>
附:watch除具备require功能外,还增了关注状态的功能
order:优先级比require和watch低,有order指定的state比没有order指定的优先级高
vim:
pkg.installed:
- order: 1</pre>
想让某个state最后一个运行,可以用last
附:state默认使用jinja(http://jinja.pocoo.org/ )的模板语法,文档地址: http://jinja.pocoo.org/docs/templates/
参考文档:http://wiki.saltstack.cn/reproduction/om-auto-salt