Puppet - 未定义的局部变量

Puppet - undefined local variable

我收到未定义的错误,但它已被定义。我确定这之前有效(可能在 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 %>