SaltStack状态管理
1、状态模块描述格式:YAML格式,文件以.sls结尾
理解YAML
https://www.unixhot.com/docs/saltstack/topics/yaml/index.html
YAML三板斧
第一:缩进。 注意,必须是两个空格。缩进代表层级关系。
第二:冒号。 与空格结合表示缩进。
冒号第二种用法是表示键值对
第三: 短横线 表示列表。 短横线后面都有空格
# cat top.sls
base:
'*':
- init.init
prod:
'linux-node*':
- cluster.haproxy-outside
- cluster.haproxy-outside-keepalived
2、模块编写存放位置
在写状态模块之前,要定义好salt环境;编辑master配置文件
vi /etc/salt/master,编辑master配置文件
找到file_roots:
定义salt的base环境。注意,修改配置文件后,一定要重启master
file_roots:
base:
- /srv/salt/base
prod:
- /srv/salt/prod
3、编写apache.sls文件
存放路径/srv/salt/web
文件作用是按照apache,并启动
apache-install:
pkg.installed:
- names:
- httpd #要安装的包名
- httpd-devel
apache-service:
service.running:
- name: httpd
- enable: True #设置开机启动
4、高级状态模块
# The state system uses a "top" file to tell the minions what environment to
# use and what modules to use. The state_top file is defined relative to the
# root of the base environment as defined in "File Server settings" below.
top.sls存放在base环境
base:
'linux-node1.example.com': #minion id
- web.apache
'linux-node2.example.com':
- web.apache
执行高级状态
salt 'linux-node1.example.com' state.highstate test=True
页:
[1]