2016-06-09 44 views
0

我試圖通過廚師將%wheel組添加到sudoers文件中。 不幸的是,我很難弄清楚這本食譜是如何工作的。 readme對我來說聽起來不太清楚。CHEF-很難弄清楚SUDO COOKBOOK的工作原理

我做了什麼:

  • 新增

    depends   'sudo' 
    

    到我的食譜

  • 添加在配方的末尾以下行的元數據文件

    node.default['authorization']['sudo']['groups'] = ['wheel'] 
    

會發生什麼(行被完全忽略):

Recipe: create-user::default 
    * yum_package[sudo] action install[2016-06-09T19:01:12+01:00] INFO: Processing yum_package[sudo] action install (create-user::default line 9) 
(up to date) 
    * user[edgarsan] action create[2016-06-09T19:01:13+01:00] INFO: Processing user[edgarsan] action create (create-user::default line 14) 
(up to date) 
    * group[wheel] action modify[2016-06-09T19:01:13+01:00] INFO: Processing group[wheel] action modify (create-user::default line 21) 
(up to date) 
    * user[banana] action create[2016-06-09T19:01:13+01:00] INFO: Processing user[banana] action create (create-user::default line 14) 
(up to date) 
    * group[wheel] action modify[2016-06-09T19:01:13+01:00] INFO: Processing group[wheel] action modify (create-user::default line 21) 
(up to date) 
[2016-06-09T19:01:13+01:00] INFO: Chef Run complete in 3.322762038 seconds 

我失去了一些東西,但我沒有找到什麼是從文檔。

在此先感謝

回答

1

您也必須通過添加以下行到你的食譜執行默認配方:

include_recipe "sudo" 

這將使用此屬性here

template "#{prefix}/sudoers" do 
    # <snip> 
    variables(
    sudoers_groups: node['authorization']['sudo']['groups'], 
    # <snip> 
) 
end 
+0

感謝您指出我到正確的方向 – ToinoBiclas

0

include_recipe "sudo"我得到以下錯誤,這就是爲什麼我首先刪除了聲明。幸運的@StephenKing讓我重新回到了正軌,給我的說法實際上是有原因的:)

================================================================================ 
Error executing action `create` on resource 'template[/sudoers]' 
================================================================================ 

    Chef::Mixin::Template::TemplateError 
    ------------------------------------ 
    undefined method `each' for nil:NilClass 

... 
    Template Context: 
    ----------------- 
    on line #4 
     2: # Do NOT modify this file directly. 
     3: 
     4: <% @sudoers_defaults.each do |defaults| -%> 
     5: Defaults  <%= defaults %> 
     6: <% end -%> 
... 

即默認並沒有傳遞給須藤配方。該解決方案由default['authorization']['sudo']['groups'] = ['wheel']屬性/ default.rb交換node.default['authorization']['sudo']['groups'] = ['wheel']食譜/ default.rb

現在一切正常