|
salt常用模块:
master端:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| test
cmd
cp
pkg
service
status
state
file
cron
disk
grains
groupadd
network
mount
pillar
virt
|
查看minion端信息:
匹配指定的主机执行命令:
1
2
3
| salt 'test*' test.ping
salt -E 'web0[0-9]' test.ping
salt -G 'os:CentOS' test.ping
|
test模块
实例:测试主机是否存活
1
2
3
4
| [iyunv@vm01 ~]# salt '*' test.ping
vm02:
True
[iyunv@vm01 ~]#
|
cmd模块
实例:运行系统命令
1
2
3
4
| [iyunv@vm01 ~]# salt '*' cmd.run 'uptime'
vm02:
18:08:06 up 4 days, 3:20, 1 user, load average: 0.00, 0.00, 0.00
[iyunv@vm01 ~]#
|
cp模块
实例:复制文件至minion端
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
| [iyunv@vm01 ~]# mkdir /srv/salt/ -p
[iyunv@vm01 ~]# cd /srv/salt/
[iyunv@vm01 salt]# ls
[iyunv@vm01 salt]# echo hello >> file.txt
[iyunv@vm01 salt]# salt '*' cp.get_file salt://file.txt /tmp/file.txt
vm02:
/tmp/file.txt
[iyunv@vm01 salt]#
[iyunv@vm01 salt]# salt '*' cmd.run 'ls /tmp'
vm02:
file.txt
[iyunv@vm01 salt]#
[iyunv@vm01 salt]# salt '*' cmd.run 'cat /tmp/file.txt'
vm02:
hello
[iyunv@vm01 salt]#
[iyunv@vm01 salt]# touch file1.txt
[iyunv@vm01 salt]# salt '*' cp.get_file salt://file1.txt /tmp/
vm02:
The minion function caused an exception: Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/minion.py", line 1200, in _thread_return
return_data = func(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/cp.py", line 200, in get_file
gzip)
File "/usr/lib/python2.6/site-packages/salt/fileclient.py", line 1047, in get_file
fn_ = salt.utils.fopen(dest, 'wb+')
File "/usr/lib/python2.6/site-packages/salt/utils/__init__.py", line 1046, in fopen
fhandle = open(*args, **kwargs)
IOError: [Errno 21] Is a directory: '/tmp/'
[iyunv@vm01 salt]#
|
#因为我没有指定文件名,所以报错了。
1
2
3
4
5
6
7
8
9
| [iyunv@vm01 salt]# salt '*' cp.get_file salt://file1.txt /tmp/file1.txt
vm02:
/tmp/file1.txt
[iyunv@vm01 salt]#
[iyunv@vm01 salt]# salt '*' cmd.run 'ls /tmp'
vm02:
file.txt
file1.txt
[iyunv@vm01 salt]#
|
pkg和service模块
实例:安装httpd软件(CentOS),运行起来
1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@vm01 ~]# salt '*' pkg.install httpd
vm02:
----------
httpd:
----------
new:
2.2.15-47.el6.centos.4
old:
[iyunv@vm01 ~]# salt '*' service.start httpd
vm02:
True
[iyunv@vm01 ~]#
|
status模块
实例:查看登陆用户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| [iyunv@vm01 ~]# salt '*' status.w
vm02:
|_
----------
idle:
14:48
jcpu:
23:43
login:
192.168.1.154
pcpu:
0.15s
tty:
pts/0
user:
xiaomo
what:
0.06s sshd: xiaomo [p
[iyunv@vm01 ~]#
|
查看salt所有模块信息:
附带官网所有的模块信息地址:
https://docs.saltstack.com/en/latest/ref/modules/all/index.html
|
|
|