首页 > 代码库 > saltsatck-grains

saltsatck-grains

grains时saltstack组件中非常重要的组件之一,grains时saltstack记录minion的一些静态信息的组件,我们可以理解未grains记录着每台minion的一些常用属性,譬如cpu,内存,磁盘,网络信息等。

[root@master ~]# salt ‘slave‘ grains.ls    //查看grains记录的信息
slave:
    - SSDs
    - biosreleasedate
    - biosversion
    - cab_u
    - cabinet
    - cpu_flags
    - cpu_model
    - cpuarch
    - deployment
    - domain
    - fqdn
    - fqdn_ip4
    - fqdn_ip6
    - gpus
    - host
    - hwaddr_interfaces
    - id
    - init
    - ip4_interfaces
    - ip6_interfaces
    - ip_interfaces
    - ipv4
    - ipv6
    - kernel
    - kernelrelease
    - locale_info
    - localhost
    - lsb_distrib_codename
    - lsb_distrib_id
    - lsb_distrib_release
    - machine_id
    - manufacturer
    - master
    - mdadm
    - mem_total
    - myname
    - nodename
    - num_cpus
    - num_gpus
    - os
    - os_family
    - osarch
    - oscodename
    - osfinger
    - osfullname
    - osmajorrelease
    - osrelease
    - osrelease_info
    - path
    - productname
    - ps
    - pythonexecutable
    - pythonpath
    - pythonversion
    - role
    - roles
    - saltpath
    - saltversion
    - saltversioninfo
    - selinux
    - serialnumber
    - server_id
    - shell
    - virtual
    - web
    - zmqversion
    
若查看grains记录的具体的值:
[root@master ~]# salt ‘slave‘ grains.items
slave:
    ----------
    SSDs:
    biosreleasedate:
        07/31/2013
        ..........
    biosversion:
  
        Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
    cpuarch:
        i686
    deployment:
        datacenter4
    domain:
    fq
        VMware, Inc.
    
    num_gpus:
        1
    os:
        CentOS
    os_family:
        RedHat

在实际的应用中,我们可以根据自己的需求定制一些grains,可采用如下的方法:

1:通过minion的设置定义;

    这种方法就是修改minion的配置文件,把配置文件“default_include: minion.d/*.conf”前的注释去掉,然后在默认的目录中写入grains脚本。

[root@slave ~]# cat /etc/salt/minion.d/grains.conf 
grains:
  roles:
    - webserver
    - memcache
  deployment: datacenter4
  cabinet: 13
  cab_u: 14-15

然后在master上运行一下:

[root@master ~]# salt ‘slave‘ grains.item roles
slave:
    ----------
    roles:
        - webserver
        - memcache
[root@master ~]# salt ‘slave‘ grains.item deployment
slave:
    ----------
    deployment:
        datacenter4



本文出自 “自定义” 博客,谢绝转载!

saltsatck-grains