上一篇说到了salt的简单安装,接下来将对学习salt相关模块进行整理和学习

Grains

Grains是存储minion基本信息的,里面存放了minion端各种系统级参数,采用静态采集方式,在minion启动时进行数据采集。可以通过
salt '*' saltutil.sync_grains 从新进行minion端静态信息的采集.

展示minion的Grains静态信息 salt '*' grains.items

newdev:
----------
SSDs:
- sda
- dm-0
- dm-1
- dm-2
biosreleasedate:
05/21/2018
biosversion:
13.3.1 (43365)
cpu_flags:
- fpu
- vme
- de
- pse
- tsc
- msr
- pae
- mce
- cx8
- apic
- sep
- mtrr
- pge
- mca
- cmov
- pat
- pse36
- clflush
- mmx
- fxsr
- sse
- sse2
- ss
- ht
- syscall
- nx
- rdtscp
- lm
- constant_tsc
- nopl
- xtopology
- nonstop_tsc
- eagerfpu
- pni
- pclmulqdq
- ssse3
- fma
- cx16
- pcid
- sse4_1
- sse4_2
- x2apic
- movbe
- popcnt
- tsc_deadline_timer
- aes
- xsave
- avx
- f16c
- rdrand
- hypervisor
- lahf_lm
- abm
- 3dnowprefetch
- fsgsbase
- tsc_adjust
- bmi1
- hle
- avx2
- smep
- bmi2
- invpcid
- mpx
- adx
- clflushopt
- xsaveopt
- dtherm
- arat
- pln
- pts
cpu_model:
Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
cpuarch:
x86_64
disks:
- sr0
dns:
----------
domain:
ip4_nameservers:
- 192.168.1.1
ip6_nameservers:
nameservers:
- 192.168.1.1
options:
search:
- lan
sortlist:
domain:
fqdn:
salt_salve_2
fqdn_ip4:
- 192.168.1.145
fqdn_ip6:
- fe80::d0f:e7bc:6a7f:a752
gid:
0
gpus:
|_
----------
model:
Accelerated Virtual Video Adapter
vendor:
unknown
groupname:
root
host:
salt_salve_2
hwaddr_interfaces:
----------
eth0:
00:1c:42:bb:de:e6
lo:
00:00:00:00:00:00
id:
newdev
init:
systemd
ip4_gw:
192.168.1.1
ip4_interfaces:
----------
eth0:
- 192.168.1.145
lo:
- 127.0.0.1
ip6_gw:
False
ip6_interfaces:
----------
eth0:
- fe80::d0f:e7bc:6a7f:a752
lo:
- ::1
ip_gw:
True
ip_interfaces:
----------
eth0:
- 192.168.1.145
- fe80::d0f:e7bc:6a7f:a752
lo:
- 127.0.0.1
- ::1
ipv4:
- 127.0.0.1
- 192.168.1.145
ipv6:
- ::1
- fe80::d0f:e7bc:6a7f:a752
kernel:
Linux
kernelrelease:
3.10.0-862.el7.x86_64
kernelversion:
#1 SMP Fri Apr 20 16:44:24 UTC 2018
locale_info:
----------
defaultencoding:
UTF-8
defaultlanguage:
en_US
detectedencoding:
UTF-8
localhost:
salt_salve_2
lsb_distrib_codename:
CentOS Linux 7 (Core)
lsb_distrib_id:
CentOS Linux
machine_id:
4759594b77c0c04fb629ee0b4da6fdbe
manufacturer:
Parallels Software International Inc.
master:
192.168.1.194
mdadm:
mem_total:
1222
nodename:
localhost.localdomain
num_cpus:
2
num_gpus:
1
os:
CentOS
os_family:
RedHat
osarch:
x86_64
oscodename:
CentOS Linux 7 (Core)
osfinger:
CentOS Linux-7
osfullname:
CentOS Linux
osmajorrelease:
7
osrelease:
7.5.1804
osrelease_info:
- 7
- 5
- 1804
path:
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
pid:
24821
productname:
Parallels Virtual Platform
ps:
ps -efHww
pythonexecutable:
/usr/bin/python
pythonpath:
- /usr/bin
- /usr/lib64/python27.zip
- /usr/lib64/python2.7
- /usr/lib64/python2.7/plat-linux2
- /usr/lib64/python2.7/lib-tk
- /usr/lib64/python2.7/lib-old
- /usr/lib64/python2.7/lib-dynload
- /usr/lib64/python2.7/site-packages
- /usr/lib/python2.7/site-packages
pythonversion:
- 2
- 7
- 5
- final
- 0
saltpath:
/usr/lib/python2.7/site-packages/salt
saltversion:
2018.3.2
saltversioninfo:
- 2018
- 3
- 2
- 0
selinux:
----------
enabled:
True
enforced:
Enforcing
serialnumber:
Parallels-4B 59 59 47 C0 77 4F C0 B6 29 EE 0B 4D A6 FD BE
server_id:
2082849409
shell:
/bin/bash
swap_total:
2047
systemd:
----------
features:
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
version:
219
uid:
0
username:
root
uuid:
4759594b-77c0-c04f-b629-ee0b4da6fdbe
virtual:
Parallels
zfs_feature_flags:
False
zfs_support:
False
zmqversion:
4.1.4

# Pillar

Pillar主要用于master端分发给minion端的信息,针对于Grains不同的是它是动态加密传输的,而且只有指定minion才能收到这些pillar信息。

通过salt '*' pillar.items 来展示pillar信息,通过salt '*' saltutil.refresh_pillar 来刷新pillar信息。

newdev:
----------
groups:
|_
----------
name:
dev
nodes:
- dev
- newdev
sshd_port:
22

High State 与 Low State

如果什么配置都没问题以后可以通过 salt '*' state.highstate 完成所有机器的部署动作。