URL中带有Puppet://的Puppet内联模板
在我的木偶模块中,我有如下内容:URL中带有Puppet://的Puppet内联模板,puppet,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
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模板。如果我为/home/carlos/code/puppet/
(代码实际存在的地方)替换puppet://
部分,它会通过,但在生产中它是/etc/puppet/
,因此它不会工作
我怎样才能做到这一点呢?RI Pienaar已经发布了一个针对具有这种行为的函数的版本。您需要在路径lib/puppet/parser/functions/multi\u source\u template.rb
中将此代码复制到一个模块中的文件中
一旦您这样做,您应该能够像这样使用它:
file {'myfile':
ensure => 'file',
path => '/whatever/myfile',
content => multi_source_template(
"my_module/${domain}/${::hostname}_myfile.erb",
"my_module/${domain}/myfile.erb"
)
}
至于原始方法不起作用的原因:URL通常仅与源属性一起使用,并按原样传输到代理。代理使用URL并向傀儡文件服务器(只是另一个主服务器)发出相应的请求
另一方面,文件
函数(此处与内容
属性以及内联模板
一起使用)将不会处理URL,而是需要本地路径
尽管如此,通过指定测试箱和生产系统的路径,问题可能已经被回避,后者只是承认缺少/home/carlos
。但这远不是一个干净的解决方案