查看所有modules模块
[root@node01 ~]# salt 'node02' sys.list_modules
node02:
- acl
- aliases
- alternatives
- ansible
- archive
- artifactory
- beacons
- bigip
- btrfs
- buildout
- chroot
- cloud
省略。。。。。。
查看指定module的所有pkg的function
[root@node01 ~]# salt 'node02' sys.list_functions pkg
node02:
- pkg.available_version
- pkg.clean_metadata
- pkg.del_repo
- pkg.diff
- pkg.download
- pkg.file_dict
- pkg.file_list
查看帮助文档
[root@node01 ~]# salt 'node02' sys.doc pkg
多个任务同时进行
[root@node01 ~]# salt 'node02' test.echo,cmd.run,service.status hello,hostname,salt-minion 这三个命令就是相当于把下面三个命令结合起来
node02:
----------
cmd.run:
node02
service.status:
True
test.echo:
hello
[root@node01 ~]# salt 'node02' test.echo hello
node02:
hello
[root@node01 ~]# salt 'node02' cmd.run 'hostname'
node02:
node02
[root@node01 ~]# salt 'node02' service.status salt-minion
node02:
True
saltstack常用模块之network
network.active_tcp 返回所有活动的tcp连接
[root@node01 ~]# salt '*' network.active_tcp
node02:
----------
0:
----------
local_addr:
192.168.175.151
local_port:
22
remote_addr:
192.168.175.1
remote_port:
51809
1:
----------
local_addr:
192.168.175.151
local_port:
22
remote_addr:
192.168.175.1
remote_port:
50356
2:
----------
local_addr:
192.168.175.151
local_port:
22
remote_addr:
192.168.175.1
remote_port:
50349
3:
----------
local_addr:
192.168.175.151
local_port:
34150
remote_addr:
192.168.175.150
remote_port:
4505
结合下面即可
[root@node02 ~]# netstat -antl
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.175.151:35472 192.168.175.150:4506 TIME_WAIT
tcp 0 0 192.168.175.151:22 192.168.175.1:51809 ESTABLISHED
tcp 0 0 192.168.175.151:22 192.168.175.1:50356 ESTABLISHED
tcp 0 48 192.168.175.151:22 192.168.175.1:50349 ESTABLISHED
tcp 0 0 192.168.175.151:34150 192.168.175.150:4505 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
network.calc_net 通过IP和子网掩码计算出网段
[root@node01 ~]# salt '*' network.calc_net 192.168.69.202 255.255.255.0
node02:
192.168.69.0/24
[root@node01 ~]# salt '*' network.calc_net 192.168.69.202 255.255.255.240
node02:
192.168.69.192/28
network.connect 测试minion至某一台服务器的网络是否连通
[root@node01 ~]# salt '*' network.connect www.baidu.com 80
node02:
----------
comment:
Successfully connected to www.baidu.com (182.61.200.7) on tcp port 80
result:
True
network.default_route 查看默认路由
[root@node01 ~]# salt '*' network.default_route
node02:
|_
----------
addr_family:
inet
destination:
0.0.0.0
flags:
UG
gateway:
192.168.175.2
interface:
ens33
netmask:
0.0.0.0
|_
----------
addr_family:
inet6
destination:
::/0
flags:
!n
gateway:
::
interface:
lo
netmask:
|_
----------
addr_family:
inet6
destination:
::/0
flags:
!n
gateway:
::
interface:
lo
netmask:
network.get_fqdn 查看主机的fqdn(完全限定域名)
[root@node01 ~]# salt '*' network.get_fqdn
node02:
node02
network.get_hostname 获取主机名
[root@node01 ~]# salt '*' network.get_hostname
node02:
node02
network.get_route 查询到一个目标网络的路由信息
[root@node01 ~]# salt '*' network.get_route 192.168.175.150
node02:
----------
destination:
192.168.175.150
gateway:
None
interface:
ens33
source:
192.168.175.151
network.hw_addr 返回指定网卡的MAC地址
[root@node01 ~]# salt '*' network.hw_addr ens33
node02:
00:0c:29:6d:98:29
network.ifacestartswith 从特定CIDR检索接口名称
[root@node01 ~]# salt '*' network.ifacestartswith 192.168
node02:
- ens33
**network.in_subnet 判断当前主机是否在某一个网段内
**
[root@node01 ~]# salt '*' network.in_subnet 192.168.175.0/24
node02:
True
network.interface 返回指定网卡的信息
[root@node01 ~]# salt '*' network.interface ens33
node02:
|_
----------
address:
192.168.175.151
broadcast:
192.168.175.255
label:
ens33
netmask:
255.255.255.0
network.interface_ip 返回指定网卡的IP地址
[root@node01 ~]# salt '*' network.interface_ip ens33
node02:
192.168.175.151
network.interfaces 返回当前系统中所有的网卡信息
[root@node01 ~]# salt '*' network.interfaces
node02:
----------
ens33:
----------
hwaddr:
00:0c:29:6d:98:29
inet:
|_
----------
address:
192.168.175.151
broadcast:
192.168.175.255
label:
ens33
netmask:
255.255.255.0
inet6:
|_
----------
address:
fe80::7790:6522:b7ac:8c7c
prefixlen:
64
scope:
link
up:
True
lo:
----------
hwaddr:
00:00:00:00:00:00
inet:
|_
----------
address:
127.0.0.1
broadcast:
None
label:
lo
netmask:
255.0.0.0
inet6:
|_
----------
address:
::1
prefixlen:
128
scope:
host
up:
True
network.ip_addrs 返回一个IPv4的地址列表
该函数将会忽略掉127.0.0.1的地址
[root@node01 ~]# salt '*' network.ip_addrs
node02:
- 192.168.175.151
network.netstat 返回所有打开的端口和状态
[root@node01 ~]# salt '*' network.netstat
node02:
|_
----------
inode:
20774
local-address:
0.0.0.0:3306
program:
1993/mysqld
proto:
tcp
recv-q:
0
remote-address:
0.0.0.0:*
send-q:
0
state:
LISTEN
user:
27
|_
----------
inode:
17309
local-address:
0.0.0.0:22
program:
1467/sshd
proto:
tcp
recv-q:
0
remote-address:
0.0.0.0:*
send-q:
0
state:
LISTEN
user:
0
|_
----------
inode:
19448
local-address:
127.0.0.1:25
program:
2421/master
proto:
tcp
recv-q:
0
remote-address:
0.0.0.0:*
send-q:
0
state:
LISTEN
user:
0
|_
----------
inode:
28022
local-address:
192.168.175.151:22
program:
3887/sshd:
proto:
tcp
recv-q:
0
remote-address:
192.168.175.1:51809
send-q:
0
state:
ESTABLISHED
user:
0
。。。。。。。。
network.ping 使用ping命令测试到某主机的连通性
[root@node01 ~]# salt '*' network.ping baidu.com
node02:
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=128 time=82.7 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=128 time