ruby - puppet getvar() 函数不工作

标签 ruby linux variables puppet

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

相关文章:

ruby-on-rails - Ruby on Rails : models, 迁移和概览

ruby - 将我的 Ruby 程序作为一体化安装程序提供

html - 如何编写一个停止/中断无限循环 Rails 应用程序的 Web 按钮?

linux - RPM-BUILD-规范文件理解

node.js - 使用 NVM( Node 版本管理器)bash : line 5: npm: command not found 安装时,Laravel Envoy 在 Ubuntu 上无法检测 Node/npm

linux - OpenVZ 更改 CentOS 6 中的默认路由

c# - 使用包含变量名称的字符串访问变量

c - 在 C 中,如何将 String 类型和 int 类型存储在同一个变量中?

android - 全局变量安全隐患

ruby-on-rails - 如何在一天中显示问候语