先看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......

ntpserver: www.example.com
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}.

09-04 15:59