07-saltstack 之pillar

pillar应用场景:敏感数据,处理变量,差异性

1.查询master的pillar,默认没有开启

[root@salt-master ~]# salt '*' pillar.items
salt-minion02:
    ----------
salt-minion01:
    ----------
salt-master:
    ----------

 2.开启pillar,编辑文件

[root@salt-master ~]# vim /etc/salt/master                # 设置为True
722 pillar_opts: True     

[root@salt-master ~]# /etc/init.d/salt-master restart   # 重启服务
Stopping salt-master daemon:                               [  OK  ]
Starting salt-master daemon:   

[root@salt-master ~]# salt '*' pillar.items                   # 可以查询到pillar
salt-minion02:
    ----------
    master:
        ----------
        __role:
            master
        archive_jobs:
            False
        auth_mode:
            1
        auto_accept:
            False
        cache:
            localfs
        cache_sreqs:

 3.自定义pillar,注释取消,设置base环境

[root@salt-master ~]# vim /etc/salt/master  # 取消注释
 694 pillar_roots:
 695   base:
 696     - /srv/pillar


[root@salt-master ~]# mkdir /srv/pillar       # 创建目录


[root@salt-master ~]# /etc/init.d/salt-master restart  # 重启服务
Stopping salt-master daemon:                               [  OK  ]
Starting salt-master daemon:                               [  OK  ]


[root@salt-master ~]# vim /srv/pillar/apache.sls   # 
{% if grains['os'] == 'CentOS' %}
apache: httpd
{% elif grains['os'] == 'Debian' %}
apache: apache2
{% endif %} 

[root@salt-master ~]# vim /srv/pillar/top.sls
base:
  '*':
    - apache

[root@salt-master ~]# salt '*' pillar.items    # 查看pillar的items,
salt-minion01:
    ----------
    apache:
        httpd
salt-master:
    ----------
    apache:
        httpd
salt-minion02:
    ----------
    apache:
        httpd

[root@salt-master ~]# salt '*' saltutil.refresh_pillar   # pillar需要刷新
salt-minion01:
    True
salt-minion02:
    True
salt-master:
    True

[root@salt-master ~]# salt -I 'apache:httpd' test.ping   # 执行
salt-minion01: 
    True
salt-minion02:
    True
salt-master:
    True

 

posted @ 2017-04-18 21:53  sunmmi  阅读(200)  评论(0)    收藏  举报