我正在查看 https://github.com/puppetlabs/puppetlabs-stdlib#getvar
我的 list
class test::var inherits stdlib {
$datalocation = 'site::data'
$bar = getvar("${datalocation}::bar")
# Equivalent to $bar = $site::data::bar
notify{"This is getvar() testing variable, Now bar equal to ${bar}":}
}
当我在客户端上运行 puppet 时,我得到一片空白
[root@401 ~]# puppet agent --test --noop
...
...
Notice: /Stage[main]/test::Var/Notify[This is getvar() testing variable, Now bar equal to '']/message: current_value absent, should be This is getvar() testing variable, Now bar equal to '' (noop)
我错过了什么吗?
最佳答案
当我运行上面的代码时,我的 puppet 输出的一部分是以下警告:
Warning: Scope(Class[Test::Var]): Could not look up qualified variable 'site::data::bar'; class site::data could not be found
这意味着 site::data::bar
在当前范围内不存在。如果您首先定义它,那么您的分配和后续通知将按预期工作。
class site::data {
$bar = 'foo'
}
class test::var inherits stdlib {
require site::data
$datalocation = 'site::data'
$bar = getvar("${datalocation}::bar")
# Equivalent to $bar = $site::data::bar
notify{"This is getvar() testing variable, Now bar equal to ${bar}":}
}
关于ruby - puppet getvar() 函数不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21531606/