Skip to content

Instantly share code, notes, and snippets.

@lithix-src
Created September 28, 2012 04:37
Show Gist options
  • Save lithix-src/3797936 to your computer and use it in GitHub Desktop.
Save lithix-src/3797936 to your computer and use it in GitHub Desktop.
def initialize(*args)
super
@action = :create
end
action :remove do
search("#{new_resource.data_bag}", "groups:#{new_resource.search_group} AND action:remove") do |rm_user|
user rm_user['id'] do
action :remove
end
end
end
action :create do
security_group = Array.new
group "#{new_resource.group_name}" do
gid new_resource.group_id
members security_group
end
search("#{new_resource.data_bag}", "groups:#{new_resource.search_group} NOT action:remove") do |u|
security_group << u['id']
if node[:apache] and node[:apache][:allowed_openids]
Array(u['openid']).compact.each do |oid|
node[:apache][:allowed_openids] << oid unless node[:apache][:allowed_openids].include?(oid)
end
end
# Set home to location in data bag,
# or a reasonable default (/home/$user).
if u['home']
home_dir = u['home']
else
home_dir = "/home/#{u['id']}"
end
# The user block will fail if the group does not yet exist.
# See the -g option limitations in man 8 useradd for an explanation.
# This should correct that without breaking functionality.
if u['gid'] and u['gid'].kind_of?(Numeric)
group u['id'] do
gid u['gid']
end
end
# Create user object.
# Do NOT try to manage null home directories.
user u['id'] do
uid u['uid']
if u['gid']
gid u['gid']
end
shell u['shell']
comment u['comment']
if home_dir == "/dev/null"
supports :manage_home => false
else
supports :manage_home => true
end
home home_dir
end
if home_dir != "/dev/null"
directory "#{home_dir}/.ssh" do
owner u['id']
group u['gid'] || u['id']
mode "0700"
end
if u['ssh_keys']
template "#{home_dir}/.ssh/authorized_keys" do
source "authorized_keys.erb"
cookbook new_resource.cookbook
owner u['id']
group u['gid'] || u['id']
mode "0600"
variables :ssh_keys => u['ssh_keys']
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment