我收到未定义的错误,但已经定义。我确定这以前是可行的(也许在puppet 3中),但是我正在尝试在puppet 6(在新服务器上)上使用该代码。
任何想法是什么问题?这是错误代码:
Error: Error while evaluating a Function Call, Failed to parse template resolv/resolv.conf.erb:\n
Filepath: /etc/puppetlabs/puppet/modules/resolv/templates/resolv.conf.erb\n Line: 1\n
Detail: undefined local variable or method `domain' for #<Puppet::Parser::TemplateWrapper:0x60d6ba83>\n
这里是代码:
class resolv {
case $hostname {
/^[Abc]/: {
resolv:resolv_config { 'Default':
domain => "mydomain.local",
}
}
}
}
define resolv::resolv_config($domain){
file { '/etc/resolv.conf':
content => template("resolv/resolv.conf.erb"),
}
}
这里是模板内容:
cat resolv.conf.erb
domain <%= domain %>
想通了。
Puppet 4+中的所有Puppet变量都必须以@开头
所以resolv.conf.erb
应该看起来像
domain <%= @domain %>