我正在运行木偶4,我想从同一个模板生成几个不同configuration的configuration文件。
例如 :
# cat /tmp/a.conf test1 # cat /tmp/b.conf test2
我需要把所有这些信息都放在hiera中,所以我想:
test::clusters: - 'a.conf' text: 'test1' - 'b.conf' text: 'test2'
谢谢
你需要一个定义的types
define test::clusters ( $text = undef ) { file { "/tmp/${title}": ensure => $ensure, owner => 'root', group => 'root', content => template('my_file/example.erb'), } }
在模板/testing/集群
<%= @text %>
然后你可以像这样在清单中定义一个test::clisters :
::test::clusters { 'a.conf': text => 'test1' }
或者,如果您仍然希望使用hiera,则可以使用create_resources
好吧,我find了如何使其工作:
这是我的hiera数据/ common.yaml:
test::paramconf: 'a': text: '1' 'b': text: '2'
这里是我的模块configuration清单/ init.pp:
class test ($paramconf){ create_resources(test::conf, $paramconf) } define test::conf ( String[1] $text, String[1] $text2 = $title, ) { file { "/tmp/${title}.conf": ensure => file, owner => 'root', group => 'root', mode => '0644', content => template('test/test2.erb'), } }
唯一我不明白的是为什么这个工作:
test::paramconf: 'a': text: '1' 'b': text: '2'
而这是行不通的:
test::paramconf: - 'a': text: '1' - 'b': text: '2'