实例
1、关闭seliunx服务
[root@test11 state]# cat service/seliunx.sls
seliunx: ##ID
file.replace: ##Function,替换文件内容的方法
- name: /etc/selinux/config ##在这里是要替换内容的文件
- pattern: SELINUX=enforcing ##要替换的内容
- repl: SELINUX=disabled ##替换后的内容
- count: 1 ##默认为0表示表示所有的都将进行替换,这里加了整数的话就表示替换的次数不超过这个整数
setenforce:
cmd.run:
- name: setenforce 0 ##这里就是cmd.run后面跟着的要执行的操作
[root@test11 state]# salt '*' state.sls service.seliunx
2、测试脚本的sls文件
[root@test11 state]# cat pyscript/init.sls
pyscript:
cmd.script:
- source: salt://pyscript/test.sh
- user: root
3、安装nginx
[root@test11 state]# cat nginx/init.sls
include: #引用的state
- repo
- user.www
- nginx.package
- nginx.config
- nginx.service
extend: #扩展那些属性
nginx: #所扩展的对象ID,在sls文件中ID唯一
pkg:
- require: #依赖谁
- file: ubox.repo
- user: www
nginx.conf:
file:
- require:
- pkg: nginx
nginx-service:
service:
- watch: #如果配置文件有修改,那么会重启nginx服务
- pkg: nginx
- file: nginx.conf
##下面为上面include引用的state.sls文件与extend所扩展的属性
[root@test11 state]# ls repo/files/
ubox-nexus.repo ubox.repo
[root@test11 state]# ls user/
test.sls www.sls
[root@test11 state]# cat user/www.sls
www: ##定义对象ID
user.present:
- shell: /sbin/nologin
- createhome: False
[root@test11 state]# cat nginx/package.sls
nginx:
pkg.installed
[root@test11 state]# cat nginx/config.sls
nginx.conf:
file.managed:
- name: /usr/local/nginx/conf/nginx.conf
- source: salt://nginx/files/nginx.conf
- user: root
- group: root
- mode: 644
- template: jinja
[root@test11 state]# cat nginx/service.sls
nginx-service:
service.running:
- name: nginx
- enable: True
- reload: True
文档更新时间: 2019-06-04 16:23 作者:子木