2.saltstack Grains与pillar使用

grains系统信息收集:
一、收集系统信息
[root@salt-master ]# salt '*salt-minion.2018.com' grains.get ip4_interfaces  #查客户端ip
salt-minion.2018.com:
    ----------
    ens33:
        - 192.168.91.133
    lo:
        - 127.0.0.1
[root@salt-master ]# salt '*salt-minion.2018.com' grains.get localhost  #查客户端主机名
salt-minion.2018.com:
    salt-minion.2018.com
[root@salt-master ]# salt '*salt-minion.2018.com' grains.get osrelease_info  #查客户端系统版本
salt-minion.2018.com:
    - 7
    - 3
    - 1611
[root@salt-master ~]# salt '*' grains.item num_cpus
salt-minion.2018.com:
    ----------
    num_cpus:
        1
salt-master.2018.com:
    ----------
    num_cpus:
        1
[root@salt-master ~]# salt '*' grains.get os
salt-minion.2018.com:
    CentOS
salt-master.2018.com:
    CentOS
[root@salt-master ~]# salt -G 'os:CentOs' test.ping
salt-minion.2018.com:
    True
salt-master.2018.com:
    True

[root@salt-master ]# salt '*salt-minion.2018.com' grains.items  #查看系统信息   <=============================         
salt-minion.2018.com:
    ----------
    SSDs:
    biosreleasedate:
        07/02/2015
    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
        - syscall
        - nx
        - pdpe1gb
        - rdtscp
        - lm
        - constant_tsc
        - arch_perfmon
        - pebs
        - bts
        - nopl
        - xtopology
        - tsc_reliable
        - nonstop_tsc
        - aperfmperf
        - eagerfpu
        - pni
        - pclmulqdq
        - ssse3
        - fma
        - cx16
        - pcid
        - sse4_1
        - sse4_2
        - x2apic
        - movbe
        - popcnt
        - tsc_deadline_timer
        - xsave
        - avx
        - f16c
        - rdrand
        - hypervisor
        - lahf_lm
        - abm
        - 3dnowprefetch
        - ida
        - arat
        - epb
        - pln
        - pts
        - dtherm
        - hwp
        - hwp_noitfy
        - hwp_act_window
        - hwp_epp
        - fsgsbase
        - tsc_adjust
        - bmi1
        - avx2
        - smep
        - bmi2
        - invpcid
        - rdseed
        - adx
        - smap
        - xsaveopt
    cpu_model:
        Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
    cpuarch:
        x86_64
    domain:
        2018.com
    fqdn:
        salt-minion.2018.com
    fqdn_ip4:
        - 192.168.91.133
    fqdn_ip6:
        - fe80::4186:9d08:9014:3f21
    gpus:
        |_
          ----------
          model:
              SVGA II Adapter
          vendor:
              unknown
    host:
        salt-minion
    hwaddr_interfaces:
        ----------
        ens33:
            00:0c:29:5c:ee:ed
        lo:
            00:00:00:00:00:00
    id:
        salt-minion.2018.com
    init:
        systemd
    ip4_interfaces:
        ----------
        ens33:
            - 192.168.91.133
        lo:
            - 127.0.0.1
    ip6_interfaces:
        ----------
        ens33:
            - fe80::4186:9d08:9014:3f21
        lo:
            - ::1
    ip_interfaces:
        ----------
        ens33:
            - 192.168.91.133
            - fe80::4186:9d08:9014:3f21
        lo:
            - 127.0.0.1
            - ::1
    ipv4:
        - 127.0.0.1
        - 192.168.91.133
    ipv6:
        - ::1
        - fe80::4186:9d08:9014:3f21
    kernel:
        Linux
    kernelrelease:
        3.10.0-514.el7.x86_64
    locale_info:
        ----------
        defaultencoding:
            UTF-8
        defaultlanguage:
            en_US
        detectedencoding:
            UTF-8
    localhost:
        salt-minion.2018.com
    lsb_distrib_id:
        CentOS Linux
    machine_id:
        dff955f75c1b4c45b397b14e762c1447
    manufacturer:
        VMware, Inc.
    master:
        192.168.91.134
    mdadm:
    mem_total:
        220
    nodename:
        salt-minion.2018.com
    num_cpus:
        1
    num_gpus:
        1
    os:
        CentOS
    os_family:
        RedHat
    osarch:
        x86_64
    oscodename:
        Core
    osfinger:
        CentOS Linux-7
    osfullname:
        CentOS Linux
    osmajorrelease:
        7
    osrelease:
        7.3.1611
    osrelease_info:
        - 7
        - 3
        - 1611
    path:
        /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
    productname:
        VMware Virtual Platform
    ps:
        ps -efH
    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:
        2015.5.10
    saltversioninfo:
        - 2015
        - 5
        - 10
        - 0
    selinux:
        ----------
        enabled:
            False
        enforced:
            Disabled
    serialnumber:
        VMware-56 4d 72 55 07 d2 02 f8-4c 89 4c 4e 74 5c ee ed
    server_id:
        229920931
    shell:
        /bin/sh
    systemd:
        ----------
        features:
            +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
        version:
            219
    virtual:
        VMware
    zmqversion:
        3.2.5
        
        
        
        
        
        
        
        
        
二、自定义:        
        
启用grains:
[root@salt-master ~]# vi /etc/salt/minion  #查到几个配置项把注稀去掉
grains:
  roles:
    - webserver
    - memcache
  env: prod
[root@salt-master ~]# systemctl restart salt-minion  #修改完配置要重启
[root@salt-master ~]# salt -G 'env:prod' test.ping
salt-master.2018.com:
    True
或者
[root@salt-master ~]# cat /etc/salt/grains
centos: abc123
[root@salt-master ~]# systemctl restart salt-minion
[root@salt-master ~]# salt -G 'centos:abc123' test.ping
salt-master.2018.com:
    True

不重启minion端 刷新grains
[root@salt-master ~]# cat /etc/salt/grains
centos: abc123
yanyb: 123
[root@salt-master ~]# salt '*' saltutil.sync_grains
salt-minion.2018.com:
salt-master.2018.com:
[root@salt-master ~]# salt -G 'yanyb:123' test.ping
salt-master.2018.com:
    True


======================================================================================================================
pillar
给minion定义想要的数据
配置管理:

1.修改master配置文件
[root@salt-master ~]# grep "pillar_opts" /etc/salt/master
pillar_roots:   #去掉这三行注稀
  base:
    - /srv/pillar
    
[root@salt-master ~]# systemctl restart salt-master  
创建
[root@salt-master ~]# mkdir /etc/salt/pillar
[root@salt-master ~]# mkdir /etc/salt/pillar/init
[root@salt-master ~]# cat /srv/pillar/top.sls
basr:
  '*':
      apache
[root@salt-master ~]# cat /srv/pillar/init/apache.sls
{% if grains['os'] == 'CentOS' %}
apache:httpd
{% eilf grains['os'] == 'Debian' %}
apache:apache2
{% endif %}

[root@salt-master pillar]# salt '*' saltutil.refresh_pillar    #刷新pillar
salt-minion.2018.com:
    True
salt-master.2018.com:
    True



    
       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值