V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
rrfeng
V2EX  ›  Puppet

Puppet 里使用 define 时的依赖关系……

  •  
  •   rrfeng · 2014-07-07 16:03:38 +08:00 · 6214 次点击
    这是一个创建于 3552 天前的主题,其中的信息可能已经有所发展或是发生改变。
    module A:
    define X {}
    class A {
    X {}
    file {}
    exec {}
    .....
    }

    module B:
    class B {
    X {}
    file {}
    service {}
    ...
    }

    即在模块 A 里定义了 X ,class A 里使用了 X;在另一个模块 B 里也使用了 X。

    节点配置如下:
    node test {
    include B
    include A
    Class['B'] -> Class['A']
    }

    ---------
    看起来没什么问题,但是在应用的时候会提示 X 未定义!
    有两种方式可以使其正常:
    1. include 的时候 A 在 B 之前;
    2. -> 关系写到 include 两者之前;

    --------------
    疑问:
    我的写法是不是不对,或者不合规范?
    define 一个公用的类型应该写在哪里?如何被引用呢?
    class 或者 resource 里已经有了 require 等参数指定了依赖关系(包括 -> ),那么为什么还跟配置文件内容的顺序有关系呢?不应该先分析依赖关系再执行吗?

    一个想法是 define X 应该写到 class A 里面,也就是 A::X 这样给其他模块使用,细想了一下上述问题仍然会存在!

    求解惑。
    第 1 条附言  ·  2014-07-07 17:29:45 +08:00
    仔细读了一遍 definition types 没找到,在 modules 文档里找到了

    Defined types can be autoloaded just like classes, and thus used from anywhere in your manifests. Like with classes, each defined type should go in its own file in a module’s manifests/ directory, and the same rules for namespacing apply.

    泪流满面~ 没有读完整文档就写真是到处跌进坑里 = =
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   999 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:52 · PVG 03:52 · LAX 12:52 · JFK 15:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.