salt pillar - storing global data in pillar

saltstack 学习之pillar
【基本介绍】
Pillar is an interface for Salt designed to offer global values that can be distributed to all minions. Pillar data is managed in a similar way as the Salt State Tree.
pillar是用来存储全局变量的,格式跟state类似

【配置】
文件:/etc/salt/master
配置pillar的路径
#####         Pillar settings        #####
##########################################
# Salt Pillars allow for the building of global data that can be made selectively
# available to different minions based on minion grain filtering. The Salt
# Pillar is laid out in the same fashion as the file server, with environments,
# a top file and sls files. However, pillar data does not need to be in the
# highstate format, and is generally just key/value pairs.

pillar_roots:
  base:
    - /srv/salt/pillar

#ext_pillar:
#  - hiera: /etc/hiera.yaml
#  - cmd_yaml: cat /etc/salt/yaml

# The pillar_gitfs_ssl_verify option specifies whether to ignore ssl certificate
# errors when contacting the pillar gitfs backend. You might want to set this to
# false if you're using a git backend that uses a self-signed certificate but
# keep in mind that setting this flag to anything other than the default of True
# is a security concern, you may want to try using the ssh transport.
#pillar_gitfs_ssl_verify: True

# The pillar_opts option adds the master configuration file data to a dict in
# the pillar called "master". This is used to set simple configurations in the
# master config file that can then be used on minions.
#pillar_opts: True


【原则】
pillar namespace
1.merge content from multiple pillar files,so long as conflicts are avoided(整合变量忽略冲突的)

【使用】
salt '*' pillar.items  还回所有的pillar
使用方法:{{ pillar['foo'] }}
          {{ salt['pillar.get']('foo', 'qux') }}

在state里面使用pillar
[root@vpn pillar]# cat top.sls 
base:
  '*':
    - packages
[root@vpn pillar]# cat packages.sls 
hn: hostname
[root@vpn pillar]# cat /srv/salt/sls_config/test.sls 
This is test:
  cmd.run:
    - name: {{ pillar['hn']}} 
[root@vpn pillar]# 



【参考】
http://docs.saltstack.com/en/latest/topics/pillar/

猜你喜欢

转载自runpanda.iteye.com/blog/2110492