CentOS 6.0 + Chef - Creating Users Group Bug

So I have started to work with Chef, which to date seems really powerful, and perhaps even better than Puppet, but the documentation is unwieldly, and it seems like everything is catered towards Debian or Ubuntu. As I've been clambering through the documentation, and making some rudimentary cookbooks to set up stacks for a project I'm on, I came across an error.

[Fri, 06 Apr 2012 00:23:22 +0900] FATAL: ArgumentError: directory[/home/username1/.ssh] (users::users line 40) had an error: ArgumentError: can't find group for username1


It seemed, that after creating a user account the recipe couldn't find the group that that user belonged to. Shelling in to the server showed that the groups were there. Googling didn't help a lot, until I found a link (Sorry to the original poster of this hack, but I've lost the link. If you send me a comment, I'd love to give you credit and a link back.)

Add this to the top of your recipe

# Hack to get groups working?

ruby_block "reset group list" do

action :nothing

block do

Etc.endgrent

end

end


And then at the end of your user creation block, you can add this line

# Implement the hack to fix the group bug.

notifies :create, resources(:ruby_block => "reset group list"), :immediately


This isn't super elegant, but it's quick, and functional.
Previous
Next Post »