带有 puppet 的 puppet 内联模板 ://in URL

标签 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/${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/

相关文章:

ruby - 如何使用puppet在服务器上设置环境变量?

recursion - puppet 递归目录创建

linux - Eyaml 和 Puppet

puppet - hiera 处理 erb 模板中 undefined variable

bash - puppet 退出代码 2,同时期望 0 with rundeck

ubuntu - 在 ubuntu 中没有 root 访问权限的 puppet 应用命令

ruby - 使用 Ruby 解析和编写 Puppet 节点定义

puppet - 确保 => 文件并确保 => 存在于 init.pp 中是否有意义

puppetserver ca 命令无法连接到 https ://puppet:8140 when using SRV record solution