【问题标题】:How do I use a chef recipe that's defined in terms of roles if I'm not using roles?如果我不使用角色,如何使用根据角色定义的厨师食谱?
【发布时间】:2014-04-24 04:31:31
【问题描述】:

我正在尝试使用Opscode ntp cookbook,但使用它的说明对我来说没有任何意义。它说:

在角色中设置 ntp 属性。例如以base.rb 角色应用于所有节点:

name 'base'
description 'Role applied to all systems'
default_attributes(
  'ntp' => {
    'servers' => ['time0.int.example.org', 'time1.int.example.org']
  }
)

然后在应用于 NTP 服务器的ntpserver.rb 角色中(例如 time.int.example.org):

name 'ntp_server'
description 'Role applied to the system that should be an NTP server.'
default_attributes(
  'ntp' => {
    'is_server'    => 'true',
    'servers'      => ['0.pool.ntp.org', '1.pool.ntp.org'],
    'peers'        => ['time0.int.example.org', 'time1.int.example.org'],
    'restrictions' => ['10.0.0.0 mask 255.0.0.0 nomodify notrap']
  }
)

在这些角色中使用的 timeX.int.example.org 应该是内部 NTP 服务器的名称或 IP 地址。然后只需将 ntp 或 ntp::default 添加到 run_list 即可应用 ntp 守护进程的配置。

我们没有在我们的配置中使用角色。我们正在编写包含其他配方的配方,然后在我们尝试配置的主机上运行适当的配方。

如何在不使用角色的情况下使用说明书?

【问题讨论】:

    标签: chef-infra


    【解决方案1】:

    您可以开发一个设置节点属性然后包含配方的包装说明书。这种包装食谱的示例食谱可能如下所示:

    # Set the node attributes for ntp
    node.default['ntp']['servers'] = ['time0.int.example.org', 'time1.int.example.org']
    
    # include the recipe
    include_recipe 'ntp'
    

    【讨论】:

    • 那行不通。出于某种原因,它似乎没有加载ntp 食谱中定义的任何默认值。我在“node['ntp']['packages'].each do |ntppkg|”上得到“nil:NilClass 的未定义方法 `each'”配方中的一行。
    • 只有在未加载原始 ntp 说明书的属性时才会发生此错误,如果您在包装说明书的 metadata.rb 中定义了 depends 'ntp',它们总是应该加载。此外,您的包装食谱应命名为 ntp 以外的名称。
    猜你喜欢
    • 2013-11-03
    • 2012-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    相关资源
    最近更新 更多