先看automatical parameter lookup,
init.pp
-
class auto (
-
$servers,
-
$autook,
-
){
-
-
file {'/tmp/foo':
-
content =>template("auto/foo.erb"),
-
}
-
}
foo.erb
-
some config snippet
-
<%= @autook %>
-
<%# comment -%>
-
<%% print a %%>
-
<% @servers.each do |s| -%>
-
<%= "ntpserver: #{s}" %>
-
<%- end -%>
# yaml
-
---
-
auto::autook: "ok"
-
auto::servers:
-
- www.example.com
-
- 0.us.pool.ntp.org
-
- 1.us.pool.ntp.org
-
- 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
-
puppet config print |grep data_binding
-
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}.
阅读(1466) | 评论(0) | 转发(0) |