ToinoBiclas
ToinoBiclas

Reputation: 262

CHEF- Having a hard time figuring out how SUDO COOKBOOK works

I was trying to add the %wheel group to the sudoers file via chef. Unfortunately i'm having an hard time to figure out how this cookbook works. The readme doesn't sound very clear to me.

What i have done:

What happens (the line gets completely ignored):

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

I'm missing something but i'm not finding out what it is from the documentation.

Thanks in advance

Upvotes: 0

Views: 338

Answers (2)

ToinoBiclas
ToinoBiclas

Reputation: 262

With include_recipe "sudo" i was getting the following error, thats the reason why i removed the statement in the first place. Fortunately @StephenKing put me back on track... and showed me that the statement was actually there for a reason :)

================================================================================
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 -%>
...

i.e. defaults were not passing to the sudo recipe. The solution was to swap node.default['authorization']['sudo']['groups'] = ['wheel'] in recipes/default.rb by default['authorization']['sudo']['groups'] = ['wheel'] in attributes/default.rb

Now everything works as expected

Upvotes: 0

StephenKing
StephenKing

Reputation: 37580

You have to also execute the default recipe by adding the following line to your recipe:

include_recipe "sudo"

This will use this attribute here:

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

Upvotes: 1

Related Questions