【发布时间】:2018-12-21 00:06:49
【问题描述】:
我有一个可以在 Hiera 中为节点设置的选项列表; mem_limit、cpu_timeout、线程...
如果它们确实存在,我需要在清单中定义的 Ruby 模板中设置它们。
清单:
file { "/etc/file.conf":
ensure => present,
owner => root,
group => root,
mode => '0644',
content => template("${module_name}/file.conf.erb")
}
文件.conf.erb:
<% if @mem_limit -%>
limit_memory=<%= @mem_limit %>
<% end -%>
<% if @cpu_timeout -%>
cpu_timeout=<%= @cpu_timeout %>
<% end -%>
<% if @threads -%>
multiple_threads=true
num_threads=<%= @threads %>
<% end -%>
我可以在清单中为每个选项添加以下内容,但如果我有十多个选项,它看起来真的很糟糕!真的希望有更好的方法来做到这一点,但努力为大量可能的选项找到一种迭代方式。
if lookup('mem_limit', undef, undef, undef) != undef {
$mem_limit = lookup('mem_limit')
}
【问题讨论】: