2014-04-23 28 views
0

我正在嘗試使用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'] 
    } 
) 

然後在ntpserver.rb作用施加到NTP服務器(例如,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守護程序的配置。

我們沒有在我們的配置中使用角色。我們正在編寫包含其他食譜的食譜,然後在我們試圖提供的主機上運行適當的食譜。

如何在不使用角色的情況下使用食譜?

回答

2

你可以開發一個包裝食譜,它設置節點屬性,然後包括配方。這種包裝食譜的示例配方可能如下所示:

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

# include the recipe 
include_recipe 'ntp' 
+0

這並不奏效。出於某種原因,它似乎沒有加載任何在'ntp'食譜中定義的默認值。我在'node'['ntp'] ['packages']中得到了'nil:NilClass'的每個'undefined方法'。each do | ntppkg |「在配方線。 –

+1

如果原始ntp食譜的屬性沒有加載,只有在你的包裝食譜的metadata.rb中定義了'depends'ntp'時,纔會出現此錯誤。另外,你的包裝食譜應該被命名爲「ntp」以外的東西。 –