如何使用迭代在Puppet 5中的hiera下迭代(未定义资源)
使用更多信息进行编辑
我想创建一个文件,将配置文本作为传递给模板的内容
这是我正在做的事情。
海埃拉
appname::app_config:
"/tmp/application.properties":
config_text:
- "# First Line"
- "Second Line"
- ""
- "So forth"
"/tmp/database.properties":
config_text:
- "Test Line"
- "Another Test Line"hiera木偶迭代配置
$appname_config.each | $config_file, Hash $config_text| {
file { "$config_file" :
ensure => present,
content => template('modulename/generic_config.epp'),
}
}模板
<% @config_text.each do |key, value| -%>
<% value.each do |key,value| -%>
<%= key %>
<% end %>
<% end -%>但我被要求使用下面的格式hiera
appname::app_config:
file: "/tmp/dummy.config"
config_text:
- "Application Properties"
- "TimePeriod = 1"
file: "/tmp/second.txt"
config_text:
- "Application Properties"
- "TimePeriod = 1"提前感谢
发布于 2020-07-05 02:47:22
第一个块中的任何内容都不会返回,例如,文件只会返回散列,这是一个哈希值,而您有重复的键,因此它将被覆盖。为了更好地了解发生了什么,您可能希望运行以下命令
class appname (
$app_config
){
notify { $app_config[file]: }
$app_config[config_text].each |$item| {
notify { $item: message => $item }
}
}它是一个散列,所以你可以使用它的键访问其中的任何东西。
https://stackoverflow.com/questions/62727077
复制相似问题