Permalink
Browse files

FC003: Check before using server-specific features

  • Loading branch information...
1 parent e5fab36 commit 22e5fdf8e9d5215847fd66757a1f7d1e5c3d60f6 Andrew Crump committed with jtimberman Mar 26, 2012
Showing with 59 additions and 51 deletions.
  1. +59 −51 providers/manage.rb
View
@@ -1,5 +1,5 @@
#
-# Cookbook Name:: users
+# Cookbook Name:: users
# Provider:: manage
#
# Copyright 2011, Eric G. Wolfe
@@ -24,74 +24,82 @@ def initialize(*args)
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
+ if Chef::Config[:solo]
+ Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
+ else
+ 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
end
action :create do
security_group = Array.new
- search("#{new_resource.data_bag}", "groups:#{new_resource.search_group} AND NOT action:remove") do |u|
- security_group << u['id']
+ if Chef::Config[:solo]
+ Chef::Log.warn("This recipe uses search. Chef Solo does not support search.")
+ else
+ 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)
+ 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
- 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']
+ # 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
- 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
+ # 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
- home home_dir
- end
- if home_dir != "/dev/null"
- directory "#{home_dir}/.ssh" do
- owner u['id']
- group u['gid'] || u['id']
- mode "0700"
+ # 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 u['ssh_keys']
- template "#{home_dir}/.ssh/authorized_keys" do
- source "authorized_keys.erb"
- cookbook new_resource.cookbook
+ if home_dir != "/dev/null"
+ directory "#{home_dir}/.ssh" do
owner u['id']
group u['gid'] || u['id']
- mode "0600"
- variables :ssh_keys => u['ssh_keys']
+ 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

0 comments on commit 22e5fdf

Please sign in to comment.