我在看https://github.com/puppetlabs/puppetlabs-stdlib#getvar
我的清单
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}":}
}
当我在客户端上运行木偶时我得空白
[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)
我错过了什么吗?
答案 0 :(得分:1)
当我运行上面的代码时,我的部分木偶输出是以下警告:
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}":}
}