在我的 Puppet 模块中,我有这样的内容:
file {'myfile':
ensure => 'file',
path => '/whatever/myfile',
content => inline_template(file(
"puppet:///modules/my_module/templates/${domain}/${::hostname}_myfile.erb",
"puppet:///modules/my_module/templates/${domain}/myfile.erb"
))
}
我的规范如下:
require 'spec_helper'
describe 'my_module' do
context 'with defaults for all parameters' do
it { should compile }
end
end
如果尝试运行它,我得到:
Failure/Error: it { should compile }
error during compilation: Evaluation Error: Error while evaluating a Function Call, Could not find any files from puppet:///modules/my_module/templates/dev.contaazul.local/myfile.erb, puppet:///modules/my_module/templates/dev.contaazul.local/myfile.erb at /home/carlos/Code/Puppet/modules/my_module/spec/fixtures/modules/my_module/manifests/init.pp:48:33 on node becker.local
显然,它找不到任何 ERB 模板。如果我将 puppet://
部分替换为 /home/carlos/Code/Puppet/
(代码实际存在的位置),它会通过,但在生产中它是 /etc/puppet/
,所以,它不会工作。
我怎样才能做到这一点?
最佳答案
RI Pienaar 发布了 code snippet对于具有这种行为的函数。您需要将此代码复制到模块之一的文件中,路径为 lib/puppet/parser/functions/multi_source_template.rb
。
一旦你这样做了,你应该能够像这样使用它:
file {'myfile':
ensure => 'file',
path => '/whatever/myfile',
content => multi_source_template(
"my_module/${domain}/${::hostname}_myfile.erb",
"my_module/${domain}/myfile.erb"
)
}
关于带有 puppet 的 puppet 内联模板 ://in URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30784078/