目录编译期间何时填充puppet类参数

目录编译期间何时填充puppet类参数,puppet,Puppet,我对类参数的明显非确定性行为有疑问。 在某些运行中,类中使用的变量已定义并包含预期值,而在另一些运行中,变量根本不存在于范围中 $ puppet config print ordering --environment test title-hash 关于木偶大师,所以我不相信这是资源排序的函数(尽管这似乎是最可能的原因) 我正在推动升级,但我需要解决这个版本(除非它是一个傀儡bug) 我的模块看起来像 $ cat mymodule/manifests/init.pp class mymodul

我对类参数的明显非确定性行为有疑问。
在某些运行中,类中使用的变量已定义并包含预期值,而在另一些运行中,变量根本不存在于范围中

$ puppet config print ordering --environment test
title-hash
关于木偶大师,所以我不相信这是资源排序的函数(尽管这似乎是最可能的原因)

我正在推动升级,但我需要解决这个版本(除非它是一个傀儡bug)

我的模块看起来像

$ 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 %>
$cat mymodule/manifests/init.pp
类mymodule(){
类{“mymodule::install”:
require=>Class['mymodule::config'],
}
}
$cat mymodule/manifests/config.pp
类mymodule::config(
$1
) {
通知{“config--param1:${param1}”:
}
$cat mymodule/manifests/install.pp
类mymodule::install(){
$local_var=$mymodule::config::param1
通知{“安装--local_var:${local_var}”:
文件{'/tmp/test_template.txt':
content=>template('mymodule/mytemplate.erb')
}
}
$cat mymodule/templates/mytemplate.erb
值=@local\u var
一切
模块类和配置类都包含在Foreman ENC中的一个节点中。我已经验证了为该节点生成的YAML,它看起来是正确的


config和install类中的notify资源总是先在config中打印,然后再在install中打印,参数总是显示在config通知中,但有时仅显示在install通知中,您
require=>Class['mymodule::config']
,但这对解析器读取清单的顺序没有影响。这就是问题所在

在查找参数值之前,需要确保类
mymodule::config
已声明

如果您依赖于类似资源的声明语法,而不是通过Hiera自动查找参数,那么实现这一点可能会非常复杂

你描述的随机性让我觉得你在某种程度上依赖于散列。Foreman是否以哈希结构传递类名?如果您的Ruby是1.8.x,您可能希望尝试一个更新的版本(稳定的散列键顺序),尽管这不足以缓解您的问题


有关评估顺序主题的全面概述,请阅读Henrik Lindberg的文章。

谢谢,这很有意义。你能给我指一些文件,当Hiera没有被使用时,可以控制申报顺序吗?我担心没有多少。解析器将从所选节点定义开始,并在首次声明每个类时对其求值。我会打电话给亨利克·林德伯格,也许他还有更多的建议。@Tanrik给我回了电话,我用一个非常相关的链接更新了答案。
$ 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 %>