简体   繁体   English

人偶定义的类型的资源是否在标准资源之后进行评估?

[英]Do puppet defined types have their resources evaluated after standard resources?

When I run the following puppet manifest using puppet 2.7.22: 当我使用人偶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': }

I receive the following output: 我收到以下输出:

$ 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

Now I understand that the puppet evaluates variables in parse order. 现在,我了解到了up按解析顺序评估变量。 I understand that it's silly to include the class b from class a after the exec which uses b's x variable. 据我所知,这是愚蠢的,包括class bclass a ,它使用B的变量x的Exec之后。 The thing I don't understand is why the exec from the defined type c (instance with name 'two') has an evaluated version of $b::x even though it appears before class 'a' in terms of parse-order. 我不明白的是,为什么定义type c (名称为“ two”的实例)的exec的评估版本为$b::x即使它在解析顺序方面出现类“ a” 之前

The only thing that would explain this would be if defined types have get delayed in terms of when they are parsed? 唯一可以解释这一点的事情是定义的类型是否在解析它们的时间上被延迟了? If this is the case, is there any documentation from puppetlabs on this (or anywhere) and/or which part of the source differentiates standard from defined type resources? 如果是这样,是否有puppetlabs提供的有关此文件(或任何地方)的文档和/或源文件的哪一部分将标准与定义的类型资源区分开? (I've tried finding it in compiler.rb but failed). (我试过在寻找它compiler.rb但失败了)。

Use before or require if you have resource dependencies that need to executed in order: 如果有需要依序执行的资源依赖项,请在之前使用或要求:

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

You can fix this problem using 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': }

Why the defined type doesn't get that warning is unknown to me and frankly I don't really care; 为什么定义的类型没有得到该警告对我来说是未知的,坦率地说,我并不在乎。 it depends on the way the Puppet compiler works. 这取决于Puppet编译器的工作方式。 If your manifest depends on such code it might break with the next version of Puppet. 如果清单依赖于此类代码,则它可能会与下一个Puppet版本一起破坏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM