saltstack学习笔记(二)数据系统

    数据系统分为Grains和Pillar

    Grains:minion启动时从minion端收集到的信息,只有启动时才会收集。又被称为静态数据。

    salt '*' grains.ls

     -  SSDs

    - cpu_flags
    - cpu_model
    - cpuarch
    - 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
    - master
    - mdadm
    - mem_total
    - nodename
    - num_cpus
    - num_gpus
    - os
    - os_family
    - osarch
    - oscodename
    - osfinger
    - osfullname
    - osmajorrelease
    - osrelease
    - osrelease_info
    - path
    - ps
    - pythonexecutable
    - pythonpath
    - pythonversion
    - saltpath
    - saltversion
    - saltversioninfo
    - selinux
    - server_id
    - shell
    - virtual

    - zmqversion

一:收集信息

[root@linux-2 files]# salt '1-82-bj-longling' grains.get fqdn
1-82-bj-longling:
    iZ2zeeq8l394wf6xol4y8aZ
[root@linux-2 files]# salt '1-82-bj-longling' grains.item fqdn
1-82-bj-longling:
    ----------
    fqdn:

        iZ2zeeq8l394wf6xol4y8aZ

二:匹配minion

   1,salt -G os:CentOS cmd.run 'w' #-G 以grains匹配 os系统

    2,修改配置文件 /etc/salt/minion或者/etc/salt/grains\

    roles:nginx#也可以写为web: nginx

    salt -G 'roles:nginx' cmd.run 'echo hehegra'

    [root@linux-2 files]# salt -G 'roles:nginx' cmd.run 'echo 0'
    linux-2.example.com:
    0

     上面两种设置方式不能同名,并且每次更改都需要重启minion服务

     3,vim /srv/salt/base/top.sls

        base:        

            'roles: nginx':

            - match: grain

            - apache           

        top.sls匹配主机执行apache.sls


    Pillar:是master端指定给特定minion端的数据,可以使用saltutil_refresh_pillar刷新,又称为动态数据。用于敏感数据保存

[root@linux-2 pillar]# salt 'linux-1.example.com' grains.get kernelrelease
linux-1.example.com:
    2.6.32-696.6.3.el6.x86_64
[root@linux-2 pillar]# salt 'linux-1.example.com' grains.get os
linux-1.example.com:
    CentOS
[root@linux-2 pillar]# salt 'linux-1.example.com' grains.get osmajorrelease
linux-1.example.com:
    6
[root@linux-2 pillar]# salt 'linux-1.example.com' grains.get osrelease
linux-1.example.com:
    6.8
[root@linux-2 pillar]#


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值