Skip to content

Instantly share code, notes, and snippets.

@spheromak
Created September 17, 2010 22:06
Show Gist options
  • Save spheromak/585044 to your computer and use it in GitHub Desktop.
Save spheromak/585044 to your computer and use it in GitHub Desktop.
module Domain
module User
#
# takes a string and gets the userdata from couch
# otherwise retuns whats passed in
#
def get_user(usr=nil)
if usr.is_a? String
usr = data_bag_item("users", usr)
end
usr
end
def remove_user(u)
user u['id'] do
action :remove
supports :manage_home => true
end
end
#
# manage a user on the system
#
def setup_user(u)
u = get_user(u)
if u['status'] =~ /remove/
remove_user(u)
elsif u['status'] =~ /lock/
elsif u['status'] =~ /unlock/
else
user u['id'] do
uid u['uid']
gid u['gid'] if u['gid']
shell get_shell(u)
comment "#{u['comment']}"
action [:create, :manage]
supports :manage_home => true
home get_home(u)
end
end
end
end
end
# if you want to use your module methods in recipe scope you may need to do this
class Chef::Recipe
include Domain::User
end
# if you want your modue methods in a specific resource you need to mix
class Chef::Resource::User
include Domain::User
end
# otherwise you can jsut
include Domain::User
foo = get_user("fred")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment