Skip to content

Instantly share code, notes, and snippets.

@btm
Created December 23, 2011 18:48
Show Gist options
  • Select an option

  • Save btm/1515049 to your computer and use it in GitHub Desktop.

Select an option

Save btm/1515049 to your computer and use it in GitHub Desktop.
# Opscode Chef recipe for configuring users that can also push configuration files and ssh keys
admin_users = search(:users, 'groups:admin')
admin_group = Array.new
admin_users.each do |u|
admin_group << u['id']
home_dir = "/home/#{u['id']}"
user u['id'] do
uid u['uid']
shell u['shell']
comment u['comment']
supports :manage_home => true
home home_dir
end
directory "#{home_dir}/.ssh" do
owner u['id']
group u['id']
mode "0700"
end
template "#{home_dir}/.ssh/authorized_keys" do
source "authorized_keys.erb"
owner u['id']
group u['id']
mode "0600"
variables :ssh_keys => u['ssh_keys']
end
if u.has_key?("files")
u["files"].each do |filename, file_data|
cookbook_file "#{home_dir}/#{filename}" do
source "#{u['id']}/#{file_data['source']}"
owner u['id']
group u['id']
mode file_data['mode']
ignore_failure true
end
end
end
end
group "admin" do
gid 5000
members admin_group
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment