]> git.openstreetmap.org Git - chef.git/blob - cookbooks/accounts/recipes/default.rb
Add missing htonl ssh auth key + add chef managed comments
[chef.git] / cookbooks / accounts / recipes / default.rb
1 # -*- coding: utf-8 -*-
2 #
3 # Cookbook Name:: accounts
4 # Recipe:: default
5 #
6 # Copyright 2010, OpenStreetMap Foundation
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 package "zsh" do
22   action :install
23 end
24
25 administrators = []
26
27 search(:accounts, "*:*").each do |account|
28   name = account["id"]
29   details = node[:accounts][:users][name] || {}
30
31   if details[:status]
32     group_members = details[:members] || account["members"] || []
33     user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
34     manage_home = details[:manage_home] || account["manage_home"] || node[:accounts][:manage_home]
35
36     group_members = group_members.collect(&:to_s).sort
37
38     case details[:status]
39     when "role"
40       user_shell = "/usr/sbin/nologin"
41     when "user", "administrator"
42       user_shell = details[:shell] || account["shell"] || node[:accounts][:shell]
43     end
44
45     group name.to_s do
46       action :create
47       gid account["uid"].to_i
48       members group_members & node[:etc][:passwd].keys
49     end
50
51     user name.to_s do
52       action :create
53       uid account["uid"].to_i
54       gid account["uid"].to_i
55       comment account["comment"] if account["comment"]
56       home user_home
57       shell user_shell
58       supports :manage_home => manage_home
59     end
60
61     remote_directory "/home/#{name}" do
62       path user_home
63       source name.to_s
64       owner name.to_s
65       group name.to_s
66       mode 0755
67       files_owner name.to_s
68       files_group name.to_s
69       files_mode 0644
70       only_if do
71         begin
72           cookbook = run_context.cookbook_collection[cookbook_name]
73           files = cookbook.relative_filenames_in_preferred_directory(node, :files, name.to_s)
74           !files.empty?
75         rescue Chef::Exceptions::FileNotFound
76           false
77         end
78       end
79     end
80
81     if details[:status] == "administrator"
82       administrators.push(name.to_s)
83     end
84   else
85     user name.to_s do
86       action :remove
87     end
88
89     group name.to_s do
90       action :remove
91     end
92   end
93 end
94
95 node[:accounts][:groups].each do |name, details|
96   group name do
97     action :modify
98     members details[:members]
99     append true
100   end
101 end
102
103 group "sudo" do
104   action :manage
105   members administrators.sort
106 end
107
108 group "admin" do
109   action :manage
110   members administrators.sort
111 end
112
113 group "adm" do
114   action :modify
115   members administrators.sort
116 end