而微软 发表于 2015-11-19 09:21:47

saltstack数据系统之Pillar

在master上面打开系统自带的pillar:
# vim /etc/salt/master
556 pillar_opts: True
# /etc/init.d/salt-master restart
Stopping salt-master daemon:                               [确定]
Starting salt-master daemon:                               [确定]

# salt '*' pillar.items               =======>显示系统自带的pillar

pillar的应用场景:
1   敏感数据:如用户名与密码
2   处理差异性变量

# vim /etc/salt/master    ==========>打开如下选项
533 pillar_roots:
534   base:
535   - /srv/pillar
556 pillar_opts: False

# mkdir pillar

# /etc/init.d/salt-master restart
Stopping salt-master daemon:                               [确定]
Starting salt-master daemon:                               [确定]

实例1:
# cat /srv/pillar/apache.sls
{% if grains['os'] == 'CentOS' %}   如果系统是CentOS
apache: httpd                         则显示httpd
{% elif grains['os'] == 'Debian' %}   如果系统是Debian
apache: apache2                     则显示apache2
{% endif %}

# cat /srv/pillar/top.sls    ========>pillar的top file文件
base:
'*':
    - apache

# salt '*' pillar.items       ========>获取pillar的值
linux-node2.example.com:
    ----------
    apache:
      httpd
linux-node1.example.com:
    ----------
    apache:
      httpd

实例2:定位主机
# salt '*' saltutil.refresh_pillar         =======>刷新pillar
linux-node1.example.com:
    True
linux-node2.example.com:
    True

# salt -I 'apache:httpd' test.ping         =========>定位主机
linux-node2.example.com:
    True
linux-node1.example.com:
    True

页: [1]
查看完整版本: saltstack数据系统之Pillar