Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1067478
  • 博文数量: 186
  • 博客积分: 4939
  • 博客等级: 上校
  • 技术积分: 2075
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-08 17:15
文章分类

全部博文(186)

文章存档

2018年(1)

2017年(3)

2016年(11)

2015年(42)

2014年(21)

2013年(9)

2012年(18)

2011年(46)

2010年(35)

分类: 系统运维

2016-08-27 19:18:08

 先看automatical parameter lookup,
init.pp
  1. class auto (
  2. $servers,
  3. $autook,
  4. ){

  5. file {'/tmp/foo':
  6.    content =>template("auto/foo.erb"),
  7. }
  8. }
foo.erb

  1. some config snippet
  2. <%= @autook %>
  3. <%# comment -%>
  4. <%% print a %%>
  5. <% @servers.each do |s| -%>
  6. <%= "ntpserver: #{s}" %>
  7. <%- end -%>
# yaml

  1. ---
  2. auto::autook: "ok"
  3. auto::servers:
  4.   - www.example.com
  5.   - 0.us.pool.ntp.org
  6.   - 1.us.pool.ntp.org
  7.   - 2.us.pool.ntp.org
结果:
some config snippet
ok......
<% print a %%>
ntpserver:
ntpserver: 0.us.pool.ntp.org
ntpserver: 1.us.pool.ntp.org
ntpserver: 2.us.pool.ntp.org

  1. puppet config print |grep data_binding
  2. data_binding_terminus = hiera

If you need to disable this feature, then you can set data_binding_terminus = none in your master’s puppet.conf

然后 :merge_behavior 在hiera.yaml里面,默认是native(在key重复的情况下,取第一个出现的), 还有个deep(不用看,官方不推荐),deeper(需要 sudo puppetserver gem install deep_merge --no-ri --no-rdoc来安装) 而deeper的行为是merge recursively; in the event of a conflict, allow higher priority values to win.
# common.yaml
---
site_users:
  bob:
    uid: 501
    shell: /bin/bash
  ash:
    uid: 502
    shell: /bin/zsh
    group: common
# %{::trusted.certname}
---
site_users:
  jen:
    uid: 503
    shell: /bin/zsh
    group: deglitch
  bob:
    uid: 1000
    group: deglitch
hierarchy里面common在最后,在deeper的行为下:
{
  "bob"=>{
    group=>"deglitch", #取第一次出现的
    uid=>1000,  # 取第一次出现的
    shell=>"/bin/bash"  # merge过来的
  },
  "jen"=>{
    group=>"deglitch",
    uid=>503
    shell=>"/bin/zsh",
  },
  "ash"=>{
    group=>"common",
    uid=>502,
    shell=>"/bin/zsh"
  }
}
还有几个函数,hiera,hiera_array, hiera_hash, 第一个可以查任意的数据类型,string/array/hash,但对于hash/array不做merge, 后2个顾名思义。hiera_include来查询class,有人把其当做ENC来用,但我不推荐。
# site.pp
hiera_include('classes') 然后在yaml写自己的名字。

smtpserver: "mail.%{scope('::domain')}"   # 用%来调用
wordpress::database_server: "%{hiera('instances::mysql::public_hostname')}" 

he literal lookup function allows you to escape ‘%{}’ in Hiera data. This is useful when you have data containing this literal string, as with some Apache variables like %{SERVER_NAME} or %{QUERY_STRING}.

阅读(1406) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~