Chef infra 如何使用';如果I';我不使用角色?
我正在尝试使用,但是使用说明对我来说没有任何意义。它说: 在角色中设置ntp属性。例如,在应用于所有节点的Chef infra 如何使用';如果I';我不使用角色?,chef-infra,Chef Infra,我正在尝试使用,但是使用说明对我来说没有任何意义。它说: 在角色中设置ntp属性。例如,在应用于所有节点的base.rb角色中: name 'base' description 'Role applied to all systems' default_attributes( 'ntp' => { 'servers' => ['time0.int.example.org', 'time1.int.example.org'] } ) 然后在应用于NTP服务器(例如ti
base.rb
角色中:
name 'base'
description 'Role applied to all systems'
default_attributes(
'ntp' => {
'servers' => ['time0.int.example.org', 'time1.int.example.org']
}
)
然后在应用于NTP服务器(例如time.int.example.org)的ntpserver.rb
角色中:
这些角色中使用的timeX.int.example.org应该是内部NTP服务器的名称或IP地址。然后只需将ntp或ntp::default添加到您的run_列表中,即可应用ntp守护程序的配置
我们没有在配置中使用角色。我们正在编写包含其他配方的配方,然后在我们试图提供的主机上运行适当的配方
如何在不使用角色的情况下使用cookbook?您可以开发一个包装器cookbook,它设置节点属性,然后包含菜谱。此类包装食谱的示例配方如下所示:
# 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
cookbook中定义的任何默认值。我在“node['ntp']['packages']上得到了“undefined method`each'for nil:NilClass”。配方中的每个do | ntppkg |”行。只有在原始ntp烹饪书的属性未加载的情况下才会发生此错误,如果您在包装器烹饪书的metadata.rb
中定义了依赖于“ntp'
,则总是会发生此错误。此外,您的包装烹饪书应该命名为ntp
以外的名称。
# Set the node attributes for ntp
node.default['ntp']['servers'] = ['time0.int.example.org', 'time1.int.example.org']
# include the recipe
include_recipe 'ntp'