Uses of grains and pillar:
Grains: Basic data information for storing minion;
Pillar: Used to store the data information that master assigns to minion.
Storage areas for grains and pillar:
Grains: Metadata is stored on the Minion side;
Pillar: Metadata is stored on the master side.
Update methods for grains and pillar:
Grains: Update at minion startup;
Pillar: Metadata is stored on the master side and refreshed with saltutil.refresh_pillar for greater efficiency and flexibility.
Simple use of 1.Grains
(1. Print all items values
[[email protected] ~]# salt ' Node2 ' grains.itemsnode2: ------- --- SSDs: biosreleasedate: 05/20/2014 biosversion: 6.00 cpu_flags: - fpu - vme - de - pse - tsc - msr - pae - mce - cx8 - apic - sep - mtrr - pge - mca - cmov - pat - pse36 - clflush - dts - mmx - fxsr - sse - sse2 - ss - ht - syscall - nx - rdtscp - lm - constant_tsc - arch_perfmon - pebs - bts - xtopology - tsc _reliable - nonstop_tsc - aperfmperf - unfair_spinlock - pni - pclmulqdq - ssse3 - cx16 - pcid - sse4_1 - sse4_2 - x2apic - popcnt - xsave - avx - f16c - hypervisor - lahf_lm - arat - epb - pln - pts - dts - fsgsbase - smep cpu_model: intel (R) corE (TM) i3-3220 CPU @ 3.30GHz cpuarch: x86_64 domain: fqdn: node2 fqdn_ip4: fqdn_ip6: gpus: |_ ---------- model: SVGA II Adapter vendor: unknown host: node2 hwaddr_interfaces: --------- - eth0: 00:50:56:25:fc:e1 lo: 00:00:00:00:00:00 id: node2 init: upstart ip4_interfaces: ---------- eth0: - 192.168.64.129 lo: - 127.0.0.1 ip6_interfaces: ---------- eth0: &nbsP; - fe80::250:56ff:fe25:fce1 lo: - ::1 ip_ interfaces: ---------- eth0: - 192.168.64.129 - fe80::250:56ff:fe25:fce1 lo: - 127.0.0.1 - ::1 ipv4: - 127.0.0.1 - 192.168.64.129 ipv6: - ::1 - fe80::250:56ff:fe25:fce1 kernel: linux kernelrelease: 2.6.32-431.el6.x86_64 locale_info: ---------- defaultencoding: UTF8 defaultlanguage: zh_ cn detectedencoding: UTF-8 localhost: node2 lsb_distrib_codename: final lsb_distrib_id: centos lsb_distrib_ release: 6.5 machine_id: 48888410126c41ba9627303a00000016 manufacturer: VMware, Inc. master: 192.168.64.128 mdadm: mem_ total: 482 nodename: node2 num_cpus: 2 num_gpus: 1 os: CentOS os_family: &nbSp redhat osarch: x86_64 oscodename: Final osfinger: CentOS-6 osfullname: CentOS osmajorrelease: 6 osrelease: 6.5 osrelease_info: - 6 - 5 path: / sbin:/usr/sbin:/bin:/usr/bin productname: VMware Virtual Platform ps: ps -efH pythonexecutable: /usr/bin/python2.6 pythonpath: - /usr/bin - /usr/lib64/python26.zip - /usr/lib64/python2.6 - /usr/lib64/python2.6/ plat-linux2 - /usr/lib64/python2.6/lib-tk - /usr/lib64/python2.6/lib-old - /usr/lib64/python2.6/lib-dynload - /usr /lib64/python2.6/site-packages - /usr/lib/python2.6/ Site-packages pythonversion: - 2 - 6 - 6 - final - 0 saltpath: /usr/lib/python2.6/site-packages/salt saltversion: 2015.5.3 saltversioninfo: - 2015 - 5 - 3 - 0 selinux: ---------- enabled: False enforced: Disabled serialnumber: vmware-56 4d 02 ba 6b 2e 3c 31-1c c4 d6 a2 66 e1 4a d2 server_id: 234795131 shell: /bin/bash virtual: vmware zmqversion: 3.2.5
(2. Print IP information and Mac information for the eth0 NIC of the Node2 node
[[email protected] ~]# Salt ' node2 ' grains.get ip4_interfaces:eth0 node2:-192.168.64.129[[email protected] ~]# salt ' Node2 ' Grains.get hwaddr_interfaces:eth0node2:00:50:56:25:fc:e1
(3. Print Node2 node System Information
#获取系统信息 [[email protected] ~]# Salt ' node2 ' grains.get osnode2:centos# get the system version [[email protected] ~]# salt ' node2 ' grains. Get osrelease node2:6.5# Get kernel version [[email protected] ~]# Salt ' node2 ' grains.get kernelreleasenode2:2.6.32-431.el 6.x86_64
Simple use of 2.Pallir
#需要创建目录 [[email protected] pillar]# pwd/srv/pillar[[email protected] pillar]# TREE -N&NBSP, .... ├── info.sls└── top.sls0 directories, 2 files# Create an info file for testing [[email protected] pillar]# cat info.sls #判断系统是否为CentOS {% if grains.os == ' CentOS ' %} #如果为CentOS, print Nginx version [content customization]nginx: nginx-1.4.7 {% endif %}# This file must be top.sls[[email protected] pillar]# cat top.sls base: ' Node2 ': #对应info. sls file name - info# Refresh Cache [Display True indicates a successful refresh] [[email protected] pillar]# salt ' Node2 ' saltutil.refresh_ pillarnode2: true #测试结果 [If the information displayed for the info file indicates success][[email protected] pillar]# salt ' Node2 ' pillar.get nginxnode2: nginx-1.4.7
It is important to note here that Pillar uses the Yaml language, and Saltstack uses Python to parse Yaml, and all that pillar is easy to understand and learn if you have a Python language ...
This article is from the "ˉt, Stand Wentao ┃﹎" blog, please be sure to keep this source http://hypocritical.blog.51cto.com/3388028/1686310
Saltstack series: Saltstack's Grains and pillar