0

当我使用 puppet 2.7.22 运行以下 puppet 清单时:

Exec {
  logoutput => true,
  path      => '/bin',
}

define c {
  exec {"echo [two]: ${b::x}": }
}

class a {
  exec {"echo [one]: ${b::x}": }
  include b
}

class b { $x = "asdf" }

c {'two': }
class {'a': }

我收到以下输出:

$ puppet apply test.pp
warning: Scope(Class[A]): Could not look up qualified variable 'b::x'; class b has not been evaluated at /tmp/l/a.pp:11
warning: Scope(Class[A]): Could not look up qualified variable 'b::x'; class b has not been evaluated at /tmp/l/a.pp:11
notice: /Stage[main]//C[two]/Exec[echo [two]: asdf]/returns: [two]: asdf
notice: /Stage[main]//C[two]/Exec[echo [two]: asdf]/returns: executed successfully
notice: /Stage[main]/A/Exec[echo [one]: ]/returns: [one]:
notice: /Stage[main]/A/Exec[echo [one]: ]/returns: executed successfully
notice: Finished catalog run in 0.15 seconds

现在我知道木偶按解析顺序评估变量。我知道在使用 b 的 x 变量的 exec 之后包含class bfrom是愚蠢的。我不明白的是,为什么定义(名称为'two'的实例)中的exec具有一个评估版本,即使它在解析顺序方面出现在类'a'之前。class atype c$b::x

唯一可以解释这一点的是,如果定义的类型在解析时被延迟了?如果是这种情况,puppetlabs 是否有任何关于此(或任何地方)的文档和/或源的哪一部分将标准与定义的类型资源区分开来?(我试过找到它compiler.rb但失败了)。

4

2 回答 2

0

如果您有需要按顺序执行的资源依赖项,请使用 before 或 require:

http://docs.puppetlabs.com/learning/ordering.html#before-and-require

于 2013-07-17T22:58:19.323 回答
0

您可以使用 require 解决此问题:

define c {
  require b
  notify {"echo [two]: ${b::x}": }
}

class a {
  require b
  notify {"echo [one]: ${b::x}": }
}

class b { $x = "asdf" }

c {'two': }
class {'a': }

我不知道为什么定义的类型没有收到警告,坦率地说我并不关心;这取决于 Puppet 编译器的工作方式。如果您的清单依赖于此类代码,则它可能会与 Puppet 的下一版本中断。

于 2013-09-25T18:35:50.253 回答