Saltstackシリーズ:SaltstackのGrainsとPillar


GrainsとPillarの用途:
Grains:minionの基本データ情報を格納するために使用されます.
Pillar:マスターが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.node 2ノードのeth 0 NICの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.node 2ノードシステム情報の印刷
# 
[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は理解しやすく、勉強しやすいということです.