[英]Do puppet defined types have their resources evaluated after standard resources?
当我使用人偶2.7.22运行以下人偶清单时:
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
现在,我了解到了up按解析顺序评估变量。 据我所知,这是愚蠢的,包括class b
从class a
,它使用B的变量x的Exec之后。 我不明白的是,为什么定义type c
(名称为“ two”的实例)的exec的评估版本为$b::x
即使它在解析顺序方面出现在类“ a” 之前 。
唯一可以解释这一点的事情是定义的类型是否在解析它们的时间上被延迟了? 如果是这样,是否有puppetlabs提供的有关此文件(或任何地方)的文档和/或源文件的哪一部分将标准与定义的类型资源区分开? (我试过在寻找它compiler.rb
但失败了)。
如果有需要依序执行的资源依赖项,请在之前使用或要求:
http://docs.puppetlabs.com/learning/ordering.html#before-and-require
您可以使用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版本一起破坏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.