SaltStack 06-SaltStack数据系统Pillar

Pillar是动态数据

  • 给特定的minion指定特定的数据(top file)
  • 只有指定的minion自己能看到自己的数据

开启系统自带的pillar数据并查看

[root@saltStack01 ~]# sed -i 's/#pillar_opts: False/pillar_opts: True/g' /etc/salt/master |grep pillar_opts:
[root@saltStack01 ~]# systemctl restart salt-master
[root@saltStack01 ~]# salt '*' pillar.items

Grains和Pillar的对比

组件 类型 数据采集方式 应用场景 定义位置
Grains 静态 minion启动时收集 数据查询、目标选择、配置管理 minion
Pillar 动态 master自定义 目标选择、配置管理、敏感数据 master

配置pillar参数

1、定义pillar的Base环境

[root@saltStack01 ~]# cat /etc/salt/master |grep -A 2 pillar_roots:
pillar_roots:
  base:
    - /srv/pillar
[root@saltStack01 ~]#

2、创建sls文件

[root@saltStack01 ~]# mkdir -p /srv/pillar
[root@saltStack01 ~]# systemctl restart salt-master
[root@saltStack01 ~]# cat /srv/pillar/top.sls 
base:
  '*salt*':
    - packages
    - services
[root@saltStack01 ~]# cat /srv/pillar/packages.sls 
zabbix:
  port: 10050
  user: zabbix
[root@saltStack01 ~]# cat /srv/pillar/services.sls 
{% if grains['os'] == 'CentOS' %}
web: apache
{% elif grains['os'] == 'Debian' %}
web: nginx
{% endif %}
[root@saltStack01 ~]#

3、刷新pillar

[root@saltStack01 ~]# salt '*salt*' saltutil.refresh_pillar

4、验证

[root@saltStack01 ~]# salt '*salt*' pillar.item zabbix
saltStack01:
    ----------
    zabbix:
        ----------
        port:
            10050
        user:
            zabbix
[root@saltStack01 ~]# salt '*salt*' pillar.item web
saltStack01:
    ----------
    web:
        apache
[root@saltStack01 ~]# salt -I 'web:apache' test.ping
saltStack01:
    True
[root@saltStack01 ~]#

pillar相关命令:

[root@saltStack01 ~]# salt '*salt*' sys.list_functions pillar
saltStack01:
    - pillar.data
    - pillar.ext
    - pillar.get
    - pillar.item
    - pillar.items
    - pillar.raw
[root@saltStack01 ~]#salt '*salt*' sys.doc pillar
原文地址:https://www.cnblogs.com/liangjingfu/p/9504523.html