Chef infra 如何首先加载当前配方属性文件?

Chef infra 如何首先加载当前配方属性文件?,chef-infra,Chef Infra,我有用于节点的配方和属性文件。例如,localhost和linode。我试图在默认属性或其他属性之前首先加载属性文件(并设置主机名等)。例如: attributes/localhost.rb: default[:hostname] = "localhost" default[:nginx][:hostname] = 'mbdev-localhost' include_attribute 'mbdev::common' 属性/common.rb default[:nginx][:website

我有用于节点的配方和属性文件。例如,localhost和linode。我试图在默认属性或其他属性之前首先加载属性文件(并设置主机名等)。例如:

attributes/localhost.rb:

default[:hostname] = "localhost"
default[:nginx][:hostname] = 'mbdev-localhost'

include_attribute 'mbdev::common'
属性/common.rb

default[:nginx][:website1][:url] = "subdomain." + default[:nginx][:hostname]
recipes/localhost.rb

include_recipe 'mbdev::default'
运行列表:

'mbdev::localhost'
但是,include_属性似乎使“common”属性首先加载。所以nginx主机名还没有设置

我得到的命令是: 1) 加载属性/default.rb 2) 加载属性/common.rb 3) 错误关于+


如何让localhost.rb在common.rb之前加载?

为什么不使用
覆盖属性
?这就是它们存在的原因:-)请参见。

默认情况下,属性文件按字母顺序加载。这一点过去并非在所有地方都完全一致,但在所有地方都得到了解决

因此,您的
attributes/common.rb
加载在
attributes/localhost.rb
之前,这仅仅是因为它按字母顺序出现在前面。该规则的一个例外是
attributes/default.rb
,它总是在烹饪书中的任何其他属性文件之前加载

通常,属性文件的加载顺序如下:

  • 按字母顺序加载所有cookbook依赖项的属性
  • 加载
    属性/default.rb
    (是否存在)
  • 按文件名的字母顺序加载任何其他属性文件
  • 通过使用
    include\u attribute
    ,可以在加载属性文件之前加载属性文件,但不能使其稍后加载

    此逻辑在chef中硬编码,无法更改。不过,您可以进行一些变通:

    • 您可以以加载顺序不再重要的方式编写属性文件
    • 您可以按照与上述逻辑一致的方式命名配方/属性
    • 可以强制重新加载属性文件:

      node.from_file(run_context.resolve_attribute("cookcook_name", "attribute_file"))
      

    这将要求我在每个主机上重复所有与主机相关的属性。然后为它定义一个角色。你刚刚解决了我的大脑障碍,关于该死的配方如何知道属性文件+如果我能。。。泰