gpt4 book ai didi

ruby - puppet getvar() 函数不工作

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:51 24 4
gpt4 key购买 nike

我正在查看 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com