我遇到类参数明显不确定的行为问题 在某些运行中,类中的used被定义并包含期望值,而在其他运行中,变量根本不存在于范围中。
$ puppet config print ordering --environment test
title-hash
在木偶大师身上,所以我不相信它是资源排序的功能(虽然这似乎是最可能的原因)。
$ puppet --verison
3.7.4
我正在推动升级,但我需要解决此版本(除非它是一个木偶错误)
我的模块看起来像......
$ cat mymodule/manifests/init.pp
class mymodule () {
class { "mymodule::install":
require => Class['mymodule::config'],
}
}
$ cat mymodule/manifests/config.pp
class mymodule::config (
$param1
) {
notify{"config -- param1: ${param1}": }
}
$ cat mymodule/manifests/install.pp
class mymodule::install () {
$local_var = $mymodule::config::param1
notify{"install -- local_var: ${local_var}": }
file {'/tmp/test_template.txt':
content => template('mymodule/mytemplate.erb')
}
}
$ cat mymodule/templates/mytemplate.erb
value = @local_var
All the things
<%= scope.to_hash.to_yaml %>
模块类和配置类都包含在Foreman ENC的节点中。我已经验证了为节点生成的YAML,看起来是正确的。
配置和安装类中的通知资源总是首先打印配置,然后是安装,参数始终显示在配置通知中,但有时仅在安装通知中显示
答案 0 :(得分:3)
您require => Class['mymodule::config']
,但这对解析器读取清单的顺序没有影响。这就是问题所在。
在查找参数值之前,您需要确保类mymodule::config
声明。
如果您依赖类似资源的声明语法而不是通过Hiera自动参数查找,那么这可能是任意复杂的。
你描述中的随机性让我觉得你在某种程度上依赖于哈希。 Foreman是否在哈希结构中传递类名?如果您的Ruby是1.8.x,您可能希望尝试更新的版本(稳定的哈希键顺序),尽管这不足以缓解您的问题。
有关评估顺序主题的全面概述,请仔细阅读Henrik Lindberg的文章Getting your Puppet Ducks in a Row。