1
2
3
|
vim:
pkg.installed:
- name: vim-enhanced
|
1
2
3
4
5
|
vim:
pkg.installed:
- names:
#多个值时,要修改为复数,names
- vim-enhanced
- lrzsz
|
1
2
3
4
5
6
7
8
|
httpd:
pkg.installed:
- name: httpd
service.running:
-
enable
: True
- require:
#一个声明,用于定义状态之间的依赖,说明httpd如果安装了,才执行service.running模块
- pkg: httpd
# pkg代表用的什么模块
|
1
2
3
|
file
.managed:
- name:
/etc/httpd/conf/httpd
.conf
-
source
: salt:
//apache/conf/httpd
.conf
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
httpd:
pkg.installed:
- name: httpd
file
.managed:
- name:
/etc/httpd/conf/httpd
.conf
-
source
: salt:
//test/httpd
.conf
- require:
- pkg: httpd
service.running:
-
enable
: True
- reload: True
-
watch
:
#监控httpd.confp文件是否发生变化,是就重新加载httpd服务
-
file
:
/etc/httpd/conf/httpd
.conf
- require:
- pkg: httpd
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
nginx_source:
file
.managed:
- name:
/tmp/nginx-1
.6.2.
tar
.gz
- unless:
test
-f
/tmp/nginx-1
.6.2.
tar
.gz
#在这里用到了unless,就是做了个判断,判断有没有这个文件,如果没有就执行nginx_source ID,否则跳过
-
source
: salt:
//test/nginx-1
.6.2.
tar
.gz
nginx_unzip:
cmd.run:
- cwd:
/tmp
- names:
tar
zxf nginx-1.6.2.
tar
.gz
- unless:
test
-d
/tmp/nginx-1
.6.2
- require:
-
file
: nginx_source
nginx_pkg:
pkg.installed:
- names:
- gcc
-
make
- openssl-devel
- pcre-devel
- zlib-devel
nginx_install:
cmd.run:
- cwd:
/tmp/nginx-1
.6.2
- name: .
/configure
--prefix=
/usr/local/nginx1
.6 &&
make
&&
make
install
&&
/usr/local/nginx1
.6
/sbin/nginx
#这一块为什么不用names呢,我也想用,可是他不是按顺序执行的,而是随机执行里面的命令的,容易造成了混乱。
- require:
#依赖两个ID状态,也就是必须有/tmp/nginx-1.6.2这个目录,和安装了gcc、make、pcre等这些依赖包,才执行nginx_install这个ID
- cmd: nginx_unzip
- pkg: nginx_pkg
- unless:
test
-d
/usr/local/nginx1
.6
|
1
2
3
4
|
file_cp:
file
.managed:
- name:
/etc/httpd/conf/httpd
.conf
-
source
: salt:
//test/httpd
.conf
|
1
2
3
4
|
tmp_cp:
file
.recurse:
- name:
/tmp
-
source
: salt:
//tmp
|
1
2
3
4
5
6
|
/opt/tmp
:
file
.directory:
- user: nginx
- group: nginx
- file_mode: 744
- makedirs: True
|
1
2
3
4
5
6
7
8
9
|
create_user:
user.present:
#用户不存在则创建,否则管理用户属性
- name: nginx
#- uid: 1501
#- gid: 1501
- createhome: False
- shell:
/sbin/nologin
#- groups:
# - nginx
|
1
2
3
|
del_user:
user.absent:
- name: abc
|
1
2
3
4
5
6
7
8
9
10
|
create_group:
group.present:
- name: abc
#- gid: 1501
- addusers:
#添加哪些用户到此组
- user1
- user2
#- delusers: #从此组中删除哪些用户
# - u1
# - u2
|
1
2
3
|
del_group:
group.absent:
- name: abc
|
1
2
3
4
5
6
|
script_cron:
cron
.present:
- name:
/bin/bash
/opt/tmp/test
.sh
- user: root
- minute: 01
- hour: 0
|