Grains和Pillar的用途:

    Grains : 用于存储minion的基本数据信息;

    Pillar : 用于存储master分配给minion的数据信息。

Grains和Pillar的存储区域:

    Grains : 元数据存储在minion端;

    Pillar : 元数据存储在master端。

Grains和Pillar的更新方式:

    Grains : 在minion启动时进行更新;

    Pillar : 元数据存储在master端,使用 saltutil.refresh_pillar进行刷新,效率更高,更为灵活。

 

1.Grains的简单使用

 (1.打印所有items值

[root@node1 ~]# salt 'node2' grains.items
node2:
    ----------
    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:
            - 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:
        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.打印node2节点的eth0网卡的ip信息和mac信息

[root@node1 ~]# salt 'node2' grains.get ip4_interfaces:eth0   
node2:
    - 192.168.64.129
[root@node1 ~]# salt 'node2' grains.get hwaddr_interfaces:eth0
node2:
    00:50:56:25:fc:e1

(3.打印node2节点系统信息

#获取系统信息
[root@node1 ~]# salt 'node2' grains.get os
node2:
    CentOS
#获取系统版本
[root@node1 ~]# salt 'node2' grains.get osrelease  
node2:
    6.5
#获取内核版本    
[root@node1 ~]# salt 'node2' grains.get kernelrelease
node2:
    2.6.32-431.el6.x86_64

2.Pallir的简单使用

#需要创建目录
[root@node1 pillar]# pwd
/srv/pillar
[root@node1 pillar]# tree -n .
.
├── info.sls
└── top.sls
0 directories, 2 files
#创建一个用于测试info文件 
[root@node1 pillar]# cat info.sls 
#判断系统是否为CentOS
{% if grains.os == 'CentOS' %}
#如果为CentOS,则打印nginx版本 [内容自定义]
nginx: nginx-1.4.7 
{% endif %}
#此文件必须为top.sls
[root@node1 pillar]# cat top.sls 
base:
  'node2':
    #对应info.sls文件名称
    - info
#刷新缓存 [显示True说明刷新成功]      
[root@node1 pillar]# salt 'node2' saltutil.refresh_pillar
node2:
    True 
#测试结果 [如果显示内容为info文件的信息,说明成功]
[root@node1 pillar]# salt 'node2' pillar.get nginx
node2:
    nginx-1.4.7

这里需要说明一下的是,pillar使用的是YAML语言,而Saltstack使用的是Python来解析YAML,所有说如果你会Python语言的话,pillar很容易理解和学习的......