blinkenstein 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.chef/knife.rb +0 -7
- data/.librarian/chef/config +2 -0
- data/Cheffile +16 -0
- data/Cheffile.lock +8 -0
- data/Gemfile +2 -0
- data/blinkenstein.gemspec +0 -3
- data/chef/cookbooks/user/.gitignore +2 -0
- data/chef/cookbooks/user/.travis.yml +6 -0
- data/chef/cookbooks/user/CHANGELOG.md +95 -0
- data/chef/cookbooks/user/README.md +391 -0
- data/chef/cookbooks/user/Rakefile +33 -0
- data/chef/cookbooks/user/attributes/default.rb +42 -0
- data/chef/cookbooks/user/metadata.json +35 -0
- data/chef/cookbooks/user/metadata.rb +14 -0
- data/chef/cookbooks/user/providers/account.rb +173 -0
- data/chef/cookbooks/user/recipes/data_bag.rb +52 -0
- data/chef/cookbooks/user/recipes/default.rb +18 -0
- data/chef/cookbooks/user/resources/account.rb +40 -0
- data/chef/cookbooks/user/templates/default/authorized_keys.erb +7 -0
- data/chef/data_bags/users/bugroger.json +9 -0
- data/chef/data_bags/users/michael.json +10 -0
- data/chef/nodes/192.168.1.110.json +1 -1
- data/chef/site-cookbooks/blinkenstein/metadata.rb +1 -0
- data/chef/site-cookbooks/blinkenstein/recipes/default.rb +7 -0
- data/lib/blinkenstein/version.rb +1 -1
- metadata +22 -35
- data/chef/cookbooks/.gitkeep +0 -0
data/.chef/knife.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
log_level :info
|
2
2
|
log_location STDOUT
|
3
|
-
node_name ENV["NODE_NAME"] || "solo"
|
4
|
-
client_key File.expand_path("../solo.pem", __FILE__)
|
5
3
|
cache_type "BasicFile"
|
6
4
|
cache_options(path: File.expand_path("../checksums", __FILE__))
|
7
5
|
cookbook_path [ File.expand_path("../../chef/cookbooks", __FILE__) ]
|
8
6
|
solo_path "chef"
|
9
|
-
# Allow users to add or override knife locally
|
10
|
-
if ::File.exist?(File.expand_path("../knife.local.rb", __FILE__))
|
11
|
-
Chef::Config.from_file(File.expand_path("../knife.local.rb", __FILE__))
|
12
|
-
end
|
13
|
-
puts File.expand_path("../../chef", __FILE__)
|
data/Cheffile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#^syntax detection
|
3
|
+
|
4
|
+
site 'http://community.opscode.com/api/v1'
|
5
|
+
|
6
|
+
# cookbook 'chef-client'
|
7
|
+
|
8
|
+
# cookbook 'apache2', '>= 1.0.0'
|
9
|
+
|
10
|
+
# cookbook 'rvm',
|
11
|
+
# :git => 'https://github.com/fnichol/chef-rvm'
|
12
|
+
|
13
|
+
# cookbook 'postgresql',
|
14
|
+
# :git => 'https://github.com/findsyou/cookbooks',
|
15
|
+
# :ref => 'postgresql-improvements'
|
16
|
+
cookbook 'user'
|
data/Cheffile.lock
ADDED
data/Gemfile
CHANGED
data/blinkenstein.gemspec
CHANGED
@@ -17,9 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_development_dependency('rspec')
|
21
|
-
gem.add_development_dependency('knife-solo')
|
22
|
-
|
23
20
|
gem.add_dependency('celluloid')
|
24
21
|
gem.add_dependency('rb-blink1')
|
25
22
|
gem.add_dependency('httparty')
|
@@ -0,0 +1,95 @@
|
|
1
|
+
## 0.3.1 (unreleased)
|
2
|
+
|
3
|
+
|
4
|
+
## 0.3.0 (July 24, 2012)
|
5
|
+
|
6
|
+
### Improvements
|
7
|
+
|
8
|
+
* Rename data_bag attribute to data_bag_name which works with bag_config cookbook. ([@fnichol][])
|
9
|
+
|
10
|
+
|
11
|
+
## 0.2.15 (July 24, 2012)
|
12
|
+
|
13
|
+
### Improvements
|
14
|
+
|
15
|
+
* Add :user_array_node_attr attribute which can override the location of the users' array in your node's attribute hash. ([@fnichol][])
|
16
|
+
|
17
|
+
|
18
|
+
## 0.2.14 (July 24, 2012)
|
19
|
+
|
20
|
+
### Improvements
|
21
|
+
|
22
|
+
* Pull request [#11](https://github.com/fnichol/chef-user/pull/11), Issue [#10](https://github.com/fnichol/chef-user/issues/10): Groups management (not only gid). ([@smaftoul][])
|
23
|
+
|
24
|
+
|
25
|
+
## 0.2.12 (May 1, 2012)
|
26
|
+
|
27
|
+
### Bug fixes
|
28
|
+
|
29
|
+
* user_account LWRP now notifies when updated (FC017). ([@fnichol][])
|
30
|
+
* Add plaform equivalents in default attrs (FC024). ([@fnichol][])
|
31
|
+
|
32
|
+
### Improvements
|
33
|
+
|
34
|
+
* Add unit testing for user_account resource. ([@fnichol][])
|
35
|
+
* Add unit testing for attributes. ([@fnichol][])
|
36
|
+
* Add TravisCI to run test suite and Foodcritic linter. ([@fnichol][])
|
37
|
+
* Reorganize README with section links. ([@fnichol][])
|
38
|
+
* Pull request [#7](https://github.com/fnichol/chef-user/pull/7): Fix semantic issues in README. ([@nathenharvey][])
|
39
|
+
|
40
|
+
|
41
|
+
## 0.2.10 (January 20, 2012)
|
42
|
+
|
43
|
+
### Bug fixes
|
44
|
+
|
45
|
+
* Pull request [#6](https://github.com/fnichol/chef-user/pull/6): Fix ordering of user deletion in :remove action. ([@nessche][])
|
46
|
+
|
47
|
+
### Improvements
|
48
|
+
|
49
|
+
* Issue [#4](https://github.com/fnichol/chef-user/issues/4): Support Ruby 1.8.6 (no #end_with?). ([@fnichol][])
|
50
|
+
* Issue [#3](https://github.com/fnichol/chef-user/issues/3): Mention dependency on ruby-shadow if managing password. ([@fnichol][])
|
51
|
+
* Issue [#5](https://github.com/fnichol/chef-user/issues/5): Clarify iteration through node['users'] in recipe[user::data_bag]. ([@fnichol][])
|
52
|
+
|
53
|
+
|
54
|
+
## 0.2.8 (January 20, 2012)
|
55
|
+
|
56
|
+
### Improvements
|
57
|
+
|
58
|
+
* Handle user names with periods in them. ([@fnichol][])
|
59
|
+
|
60
|
+
|
61
|
+
## 0.2.6 (October 18, 2011)
|
62
|
+
|
63
|
+
### Improvements
|
64
|
+
|
65
|
+
* Data bag item attribute `username` can override `id` for users with illegal data bag characters. ([@fnichol])
|
66
|
+
|
67
|
+
|
68
|
+
## 0.2.4 (September 19, 2011)
|
69
|
+
|
70
|
+
### Bug fixes
|
71
|
+
|
72
|
+
* Fix data bag missing error message. ([@fnichol][])
|
73
|
+
|
74
|
+
|
75
|
+
## 0.2.2 (September 14, 2011)
|
76
|
+
|
77
|
+
### Bug fixes
|
78
|
+
|
79
|
+
* Issue [#2](https://github.com/fnichol/chef-user/issues/2): user_account resource should accept String or Integer for uid attribute. ([@fnichol][])
|
80
|
+
* Add home and shell defaults for SuSE. ([@fnichol][])
|
81
|
+
|
82
|
+
### Improvements
|
83
|
+
|
84
|
+
* Add installation instructions to README. ([@fnichol][])
|
85
|
+
* Add fallback default `home_root` attribute value of "/home". ([@fnichol][])
|
86
|
+
|
87
|
+
|
88
|
+
## 0.2.0 (August 12, 2011)
|
89
|
+
|
90
|
+
The initial release.
|
91
|
+
|
92
|
+
[@fnichol]: https://github.com/fnichol
|
93
|
+
[@nathenharvey]: https://github.com/nathenharvey
|
94
|
+
[@nessche]: https://github.com/nessche
|
95
|
+
[@smaftoul]: https://github.com/smaftoul
|
@@ -0,0 +1,391 @@
|
|
1
|
+
# <a name="title"></a> chef-user [](http://travis-ci.org/fnichol/chef-user)
|
2
|
+
|
3
|
+
## <a name="description"></a> Description
|
4
|
+
|
5
|
+
A convenient Chef LWRP to manage user accounts and SSH keys. This is **not**
|
6
|
+
the Opscode *users* cookbook.
|
7
|
+
|
8
|
+
* Github: https://github.com/fnichol/chef-user
|
9
|
+
* Opscode Community Site: http://community.opscode.com/cookbooks/user
|
10
|
+
|
11
|
+
## <a name="usage"></a> Usage
|
12
|
+
|
13
|
+
Simply include `recipe[user]` in your run\_list and the `user_account`
|
14
|
+
resource will be available.
|
15
|
+
|
16
|
+
To use `recipe[user::data_bag]`, include it in your run\_list and have a
|
17
|
+
data bag called `"users"` with an item like the following:
|
18
|
+
|
19
|
+
{
|
20
|
+
"id" : "hsolo",
|
21
|
+
"comment" : "Han Solo",
|
22
|
+
"home" : "/opt/hoth/hsolo",
|
23
|
+
"ssh_keys" : ["123...", "456..."]
|
24
|
+
}
|
25
|
+
|
26
|
+
or a user to be removed:
|
27
|
+
|
28
|
+
{
|
29
|
+
"id" : "lando",
|
30
|
+
"action" : "remove"
|
31
|
+
}
|
32
|
+
|
33
|
+
The data bag recipe will iterate through a list of usernames defined in
|
34
|
+
`node['users']` (by default) and attempt to pull in the user's information
|
35
|
+
from the data bag item. In other words, having:
|
36
|
+
|
37
|
+
node['users'] = ['hsolo']
|
38
|
+
|
39
|
+
will set up the `hsolo` user information and not use the `lando` user
|
40
|
+
information.
|
41
|
+
|
42
|
+
## <a name="requirements"></a> Requirements
|
43
|
+
|
44
|
+
### <a name="requirements-chef"></a> Chef
|
45
|
+
|
46
|
+
Tested on 0.10.8 but newer and older version should work just fine. File an
|
47
|
+
[issue][issues] if this isn't the case.
|
48
|
+
|
49
|
+
### <a name="requirements-platform"></a> Platform
|
50
|
+
|
51
|
+
The following platforms have been tested with this cookbook, meaning that the
|
52
|
+
recipes run on these platforms without error:
|
53
|
+
|
54
|
+
* ubuntu
|
55
|
+
* debian
|
56
|
+
* mac_os_x
|
57
|
+
|
58
|
+
### <a name="requirements-cookbooks"></a> Cookbooks
|
59
|
+
|
60
|
+
There are **no** external cookbook dependencies.
|
61
|
+
|
62
|
+
## <a name="installation"></a> Installation
|
63
|
+
|
64
|
+
Depending on the situation and use case there are several ways to install
|
65
|
+
this cookbook. All the methods listed below assume a tagged version release
|
66
|
+
is the target, but omit the tags to get the head of development. A valid
|
67
|
+
Chef repository structure like the [Opscode repo][chef_repo] is also assumed.
|
68
|
+
|
69
|
+
### <a name="installation-platform"></a> From the Opscode Community Platform
|
70
|
+
|
71
|
+
To install this cookbook from the Opscode platform, use the *knife* command:
|
72
|
+
|
73
|
+
knife cookbook site install user
|
74
|
+
|
75
|
+
### <a name="installation-librarian"></a> Using Librarian-Chef
|
76
|
+
|
77
|
+
[Librarian-Chef][librarian] is a bundler for your Chef cookbooks.
|
78
|
+
Include a reference to the cookbook in a [Cheffile][cheffile] and run
|
79
|
+
`librarian-chef install`. To install Librarian-Chef:
|
80
|
+
|
81
|
+
gem install librarian
|
82
|
+
cd chef-repo
|
83
|
+
librarian-chef init
|
84
|
+
|
85
|
+
To use the Opscode platform version:
|
86
|
+
|
87
|
+
echo "cookbook 'user'" >> Cheffile
|
88
|
+
librarian-chef install
|
89
|
+
|
90
|
+
Or to reference the Git version:
|
91
|
+
|
92
|
+
cat >> Cheffile <<END_OF_CHEFFILE
|
93
|
+
cookbook 'user',
|
94
|
+
:git => 'git://github.com/fnichol/chef-user.git', :ref => 'v0.3.0'
|
95
|
+
END_OF_CHEFFILE
|
96
|
+
librarian-chef install
|
97
|
+
|
98
|
+
### <a name="installation-kgc"></a> Using knife-github-cookbooks
|
99
|
+
|
100
|
+
The [knife-github-cookbooks][kgc] gem is a plugin for *knife* that supports
|
101
|
+
installing cookbooks directly from a GitHub repository. To install with the
|
102
|
+
plugin:
|
103
|
+
|
104
|
+
gem install knife-github-cookbooks
|
105
|
+
cd chef-repo
|
106
|
+
knife cookbook github install fnichol/chef-user/v0.3.0
|
107
|
+
|
108
|
+
### <a name="installation-gitsubmodule"></a> As a Git Submodule
|
109
|
+
|
110
|
+
A common practice (which is getting dated) is to add cookbooks as Git
|
111
|
+
submodules. This is accomplishes like so:
|
112
|
+
|
113
|
+
cd chef-repo
|
114
|
+
git submodule add git://github.com/fnichol/chef-user.git cookbooks/user
|
115
|
+
git submodule init && git submodule update
|
116
|
+
|
117
|
+
**Note:** the head of development will be linked here, not a tagged release.
|
118
|
+
|
119
|
+
### <a name="installation-tarball"></a> As a Tarball
|
120
|
+
|
121
|
+
If the cookbook needs to downloaded temporarily just to be uploaded to a Chef
|
122
|
+
Server or Opscode Hosted Chef, then a tarball installation might fit the bill:
|
123
|
+
|
124
|
+
cd chef-repo/cookbooks
|
125
|
+
curl -Ls https://github.com/fnichol/chef-user/tarball/v0.3.0 | tar xfz - && \
|
126
|
+
mv fnichol-chef-user-* user
|
127
|
+
|
128
|
+
## <a name="recipes"></a> Recipes
|
129
|
+
|
130
|
+
### <a name="recipes-default"></a> default
|
131
|
+
|
132
|
+
This recipe is a no-op and does nothing.
|
133
|
+
|
134
|
+
### <a name="recipes-data-bag"></a> default
|
135
|
+
|
136
|
+
Processes a list of users with data drawn from a data bag. The default data bag
|
137
|
+
is `users` and the list of user account to create on this node is set on
|
138
|
+
`node['users']`.
|
139
|
+
|
140
|
+
## <a name="attributes"></a> Attributes
|
141
|
+
|
142
|
+
### <a name="attributes-home-root"></a> home_root
|
143
|
+
|
144
|
+
The default parent path of a user's home directory. Each resource can override
|
145
|
+
this value which varies by platform. Generally speaking, the default value is
|
146
|
+
`"/home"`.
|
147
|
+
|
148
|
+
### <a name="attributes-default-shell"></a> default_shell
|
149
|
+
|
150
|
+
The default user shell given to a user. Each resource can override this value
|
151
|
+
which varies by platform. Generally speaking, the default value is
|
152
|
+
`"/bin/bash"`.
|
153
|
+
|
154
|
+
### <a name="attributes-manage-home"></a> manage_home
|
155
|
+
|
156
|
+
Whether of not to manage the home directory of a user by default. Each resource
|
157
|
+
can override this value. The are 2 valid states:
|
158
|
+
|
159
|
+
* `"true"`, `true`, or `"yes"`: will manage the user's home directory.
|
160
|
+
* `"false"`, `false`, or `"no"`: will not manage the user's home directory.
|
161
|
+
|
162
|
+
The default is `true`.
|
163
|
+
|
164
|
+
### <a name="attributes-create-user-group"></a> create_user_group
|
165
|
+
|
166
|
+
Whether or not to to create a group with the same name as the user by default.
|
167
|
+
Each resource can override this value. The are 2 valid states:
|
168
|
+
|
169
|
+
* `"true"`, `true`, or `"yes"`: will create a group for the user by default.
|
170
|
+
* `"false"`, `false`, or `"no"`: will not create a group for the user by default.
|
171
|
+
|
172
|
+
The default is `true`.
|
173
|
+
|
174
|
+
### <a name="attributes-ssh-keygen"></a> ssh_keygen
|
175
|
+
|
176
|
+
Whether or not to generate an SSH keypair for the user by default. Each
|
177
|
+
resource can override this value. There are 2 valid states:
|
178
|
+
|
179
|
+
* `"true"`, `true`, or `"yes"`: will generate an SSH keypair when the account
|
180
|
+
is created.
|
181
|
+
* `"false"`, `false`, or `"no"`: will not generate an SSH keypair when the account
|
182
|
+
is created.
|
183
|
+
|
184
|
+
The default is `true`.
|
185
|
+
|
186
|
+
### <a name="attributes-data-bag-name"></a> data_bag_name
|
187
|
+
|
188
|
+
The data bag name containing a group of user account information. This is used
|
189
|
+
by the `data_bag` recipe to use as a database of user accounts.
|
190
|
+
|
191
|
+
The default is `"users"`.
|
192
|
+
|
193
|
+
### <a name="attributes-user-array-node-attr"></a> user_array_node_attr
|
194
|
+
|
195
|
+
The node attributes containing an array of users to be managed. If a nested
|
196
|
+
hash in the node's attributes is required, then use a `/` between subhashes.
|
197
|
+
For example, if the users' array is stored in `node['system']['accounts']`),
|
198
|
+
then set `node['user']['user_array_node_attr']` to `"system/accounts"`.
|
199
|
+
|
200
|
+
The default is `"users"`.
|
201
|
+
|
202
|
+
## <a name="lwrps"></a> Resources and Providers
|
203
|
+
|
204
|
+
### <a name="lwrps-ua"></a> user_account
|
205
|
+
|
206
|
+
**Note:** in order to use the `password` attribute, you must have the
|
207
|
+
[ruby-shadow gem][ruby-shadow_gem] installed. On Debian/Ubuntu you can get
|
208
|
+
this by installing the "libshadow-ruby1.8" package.
|
209
|
+
|
210
|
+
### <a name="lwrps-ua-actions"></a> Actions
|
211
|
+
|
212
|
+
<table>
|
213
|
+
<thead>
|
214
|
+
<tr>
|
215
|
+
<th>Action</th>
|
216
|
+
<th>Description</th>
|
217
|
+
<th>Default</th>
|
218
|
+
</tr>
|
219
|
+
</thead>
|
220
|
+
<tbody>
|
221
|
+
<tr>
|
222
|
+
<td>create</td>
|
223
|
+
<td>
|
224
|
+
Create the user, its home directory, <code>.ssh/authorized_keys</code>,
|
225
|
+
and <code>.ssh/{id_dsa,id_dsa.pub}</code>.
|
226
|
+
</td>
|
227
|
+
<td>Yes</td>
|
228
|
+
</tr>
|
229
|
+
<tr>
|
230
|
+
<td>remove</td>
|
231
|
+
<td>Remove the user account.</td>
|
232
|
+
<td> </td>
|
233
|
+
</tr>
|
234
|
+
<tr>
|
235
|
+
<td>modify</td>
|
236
|
+
<td>Modiy the user account.</td>
|
237
|
+
<td> </td>
|
238
|
+
</tr>
|
239
|
+
<tr>
|
240
|
+
<td>manage</td>
|
241
|
+
<td>Manage the user account.</td>
|
242
|
+
<td> </td>
|
243
|
+
</tr>
|
244
|
+
<tr>
|
245
|
+
<td>lock</td>
|
246
|
+
<td>Lock the user's password.</td>
|
247
|
+
<td> </td>
|
248
|
+
</tr>
|
249
|
+
<tr>
|
250
|
+
<td>unlock</td>
|
251
|
+
<td>Unlock the user's password.</td>
|
252
|
+
<td> </td>
|
253
|
+
</tr>
|
254
|
+
</tbody>
|
255
|
+
</table>
|
256
|
+
|
257
|
+
### <a name="lwrps-ua-attributes"></a> Attributes
|
258
|
+
|
259
|
+
<table>
|
260
|
+
<thead>
|
261
|
+
<tr>
|
262
|
+
<th>Attribute</th>
|
263
|
+
<th>Description</th>
|
264
|
+
<th>Default Value</th>
|
265
|
+
</tr>
|
266
|
+
</thead>
|
267
|
+
<tbody>
|
268
|
+
<tr>
|
269
|
+
<td>username</td>
|
270
|
+
<td><b>Name attribute:</b> The name of the user.</td>
|
271
|
+
<td><code>nil</code></td>
|
272
|
+
</tr>
|
273
|
+
<tr>
|
274
|
+
<td>comment</td>
|
275
|
+
<td>Gecos/Comment field.</td>
|
276
|
+
<td><code>nil</code></td>
|
277
|
+
</tr>
|
278
|
+
<tr>
|
279
|
+
<td>uid</td>
|
280
|
+
<td>The numeric user id.</td>
|
281
|
+
<td><code>nil</code></td>
|
282
|
+
</tr>
|
283
|
+
<tr>
|
284
|
+
<td>gid</td>
|
285
|
+
<td>The primary group id.</td>
|
286
|
+
<td><code>nil</code></td>
|
287
|
+
</tr>
|
288
|
+
<tr>
|
289
|
+
<td>home</td>
|
290
|
+
<td>Home directory location.</td>
|
291
|
+
<td><code>"#{node['user']['home_root']}/#{username}</code></td>
|
292
|
+
</tr>
|
293
|
+
<tr>
|
294
|
+
<td>shell</td>
|
295
|
+
<td>The login shell.</td>
|
296
|
+
<td><code>node['user']['default_shell']</code></td>
|
297
|
+
</tr>
|
298
|
+
<tr>
|
299
|
+
<td>password</td>
|
300
|
+
<td>Shadow hash of password.</td>
|
301
|
+
<td><code>nil</code></td>
|
302
|
+
</tr>
|
303
|
+
<tr>
|
304
|
+
<td>system_user</td>
|
305
|
+
<td>Whether or not to create a system user.</td>
|
306
|
+
<td><code>false</code></td>
|
307
|
+
</tr>
|
308
|
+
<tr>
|
309
|
+
<td>manage_home</td>
|
310
|
+
<td>Whether or not to manage the home directory.</td>
|
311
|
+
<td><code>true</code></td>
|
312
|
+
</tr>
|
313
|
+
<tr>
|
314
|
+
<td>create_group</td>
|
315
|
+
<td>
|
316
|
+
Whether or not to to create a group with the same name as the user.
|
317
|
+
</td>
|
318
|
+
<td><code>node['user']['create_group']</code></td>
|
319
|
+
</tr>
|
320
|
+
<tr>
|
321
|
+
<td>ssh_keys</td>
|
322
|
+
<td>
|
323
|
+
A <b>String</b> or <b>Array</b> of SSH public keys to populate the
|
324
|
+
user's <code>.ssh/authorized_keys</code> file.
|
325
|
+
</td>
|
326
|
+
<td><code>[]</code></td>
|
327
|
+
</tr>
|
328
|
+
<tr>
|
329
|
+
<td>ssh_keygen</td>
|
330
|
+
<td>Whether or not to generate an SSH keypair for the user.</td>
|
331
|
+
<td><code>node['user']['ssh_keygen']</code></td>
|
332
|
+
</tr>
|
333
|
+
</tbody>
|
334
|
+
</table>
|
335
|
+
|
336
|
+
#### <a name="lwrps-ua-examples"></a> Examples
|
337
|
+
|
338
|
+
##### Creating a User Account
|
339
|
+
|
340
|
+
user_account 'hsolo' do
|
341
|
+
comment 'Han Solo'
|
342
|
+
ssh_keys ['3dc348d9af8027df7b9c...', '2154d3734d609eb5c452...']
|
343
|
+
home '/opt/hoth/hsolo'
|
344
|
+
end
|
345
|
+
|
346
|
+
##### Locking a User Account
|
347
|
+
|
348
|
+
user_account 'lando' do
|
349
|
+
action :lock
|
350
|
+
end
|
351
|
+
|
352
|
+
##### Removing a User account
|
353
|
+
|
354
|
+
user_account 'obiwan' do
|
355
|
+
action :remove
|
356
|
+
end
|
357
|
+
|
358
|
+
## <a name="development"></a> Development
|
359
|
+
|
360
|
+
* Source hosted at [GitHub][repo]
|
361
|
+
* Report issues/Questions/Feature requests on [GitHub Issues][issues]
|
362
|
+
|
363
|
+
Pull requests are very welcome! Make sure your patches are well tested.
|
364
|
+
Ideally create a topic branch for every separate change you make.
|
365
|
+
|
366
|
+
## <a name="license"></a> License and Author
|
367
|
+
|
368
|
+
Author:: [Fletcher Nichol][fnichol] (<fnichol@nichol.ca>) [](http://coderwall.com/fnichol)
|
369
|
+
|
370
|
+
Copyright 2011, Fletcher Nichol
|
371
|
+
|
372
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
373
|
+
you may not use this file except in compliance with the License.
|
374
|
+
You may obtain a copy of the License at
|
375
|
+
|
376
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
377
|
+
|
378
|
+
Unless required by applicable law or agreed to in writing, software
|
379
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
380
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
381
|
+
See the License for the specific language governing permissions and
|
382
|
+
limitations under the License.
|
383
|
+
|
384
|
+
[chef_repo]: https://github.com/opscode/chef-repo
|
385
|
+
[cheffile]: https://github.com/applicationsonline/librarian/blob/master/lib/librarian/chef/templates/Cheffile
|
386
|
+
[kgc]: https://github.com/websterclay/knife-github-cookbooks#readme
|
387
|
+
[librarian]: https://github.com/applicationsonline/librarian#readme
|
388
|
+
[ruby-shadow_gem]: https://rubygems.org/gems/ruby-shadow
|
389
|
+
|
390
|
+
[repo]: https://github.com/fnichol/chef-user
|
391
|
+
[issues]: https://github.com/fnichol/chef-user/issues
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs.push "lib"
|
6
|
+
t.test_files = FileList['test/**/*_spec.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Runs foodcritc linter"
|
11
|
+
task :foodcritic do
|
12
|
+
if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup)
|
13
|
+
sandbox = File.join(File.dirname(__FILE__), %w{tmp foodcritic cookbook})
|
14
|
+
prepare_foodcritic_sandbox(sandbox)
|
15
|
+
|
16
|
+
sh "foodcritic --epic-fail any #{File.dirname(sandbox)}"
|
17
|
+
else
|
18
|
+
puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
task :default => 'test'
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def prepare_foodcritic_sandbox(sandbox)
|
27
|
+
files = %w{*.md *.rb attributes definitions files providers
|
28
|
+
recipes resources templates}
|
29
|
+
|
30
|
+
rm_rf sandbox
|
31
|
+
mkdir_p sandbox
|
32
|
+
cp_r Dir.glob("{#{files.join(',')}}"), sandbox
|
33
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: user
|
3
|
+
# Attributes:: default
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2011, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
case platform
|
23
|
+
when 'debian','ubuntu','redhat','centos','amazon','scientific','fedora','freebsd','suse'
|
24
|
+
default['user']['home_root'] = "/home"
|
25
|
+
default['user']['default_shell'] = "/bin/bash"
|
26
|
+
when 'openbsd'
|
27
|
+
default['user']['home_root'] = "/home"
|
28
|
+
default['user']['default_shell'] = "/bin/ksh"
|
29
|
+
when 'mac_os_x', 'mac_os_x_server'
|
30
|
+
default['user']['home_root'] = "/Users"
|
31
|
+
default['user']['default_shell'] = "/bin/bash"
|
32
|
+
else
|
33
|
+
default['user']['home_root'] = "/home"
|
34
|
+
default['user']['default_shell'] = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
default['user']['manage_home'] = "true"
|
38
|
+
default['user']['create_user_group'] = "true"
|
39
|
+
default['user']['ssh_keygen'] = "true"
|
40
|
+
|
41
|
+
default['user']['data_bag_name'] = "users"
|
42
|
+
default['user']['user_array_node_attr'] = "users"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"name": "user",
|
3
|
+
"description": "A convenient Chef LWRP to manage user accounts and SSH keys (this is not the opscode users cookbook)",
|
4
|
+
"long_description": "# <a name=\"title\"></a> chef-user [](http://travis-ci.org/fnichol/chef-user)\n\n## <a name=\"description\"></a> Description\n\nA convenient Chef LWRP to manage user accounts and SSH keys. This is **not**\nthe Opscode *users* cookbook.\n\n* Github: https://github.com/fnichol/chef-user\n* Opscode Community Site: http://community.opscode.com/cookbooks/user\n\n## <a name=\"usage\"></a> Usage\n\nSimply include `recipe[user]` in your run\\_list and the `user_account`\nresource will be available.\n\nTo use `recipe[user::data_bag]`, include it in your run\\_list and have a\ndata bag called `\"users\"` with an item like the following:\n\n {\n \"id\" : \"hsolo\",\n \"comment\" : \"Han Solo\",\n \"home\" : \"/opt/hoth/hsolo\",\n \"ssh_keys\" : [\"123...\", \"456...\"]\n }\n\nor a user to be removed:\n\n {\n \"id\" : \"lando\",\n \"action\" : \"remove\"\n }\n\nThe data bag recipe will iterate through a list of usernames defined in\n`node['users']` (by default) and attempt to pull in the user's information\nfrom the data bag item. In other words, having:\n\n node['users'] = ['hsolo']\n\nwill set up the `hsolo` user information and not use the `lando` user\ninformation.\n\n## <a name=\"requirements\"></a> Requirements\n\n### <a name=\"requirements-chef\"></a> Chef\n\nTested on 0.10.8 but newer and older version should work just fine. File an\n[issue][issues] if this isn't the case.\n\n### <a name=\"requirements-platform\"></a> Platform\n\nThe following platforms have been tested with this cookbook, meaning that the\nrecipes run on these platforms without error:\n\n* ubuntu\n* debian\n* mac_os_x\n\n### <a name=\"requirements-cookbooks\"></a> Cookbooks\n\nThere are **no** external cookbook dependencies.\n\n## <a name=\"installation\"></a> Installation\n\nDepending on the situation and use case there are several ways to install\nthis cookbook. All the methods listed below assume a tagged version release\nis the target, but omit the tags to get the head of development. A valid\nChef repository structure like the [Opscode repo][chef_repo] is also assumed.\n\n### <a name=\"installation-platform\"></a> From the Opscode Community Platform\n\nTo install this cookbook from the Opscode platform, use the *knife* command:\n\n knife cookbook site install user\n\n### <a name=\"installation-librarian\"></a> Using Librarian-Chef\n\n[Librarian-Chef][librarian] is a bundler for your Chef cookbooks.\nInclude a reference to the cookbook in a [Cheffile][cheffile] and run\n`librarian-chef install`. To install Librarian-Chef:\n\n gem install librarian\n cd chef-repo\n librarian-chef init\n\nTo use the Opscode platform version:\n\n echo \"cookbook 'user'\" >> Cheffile\n librarian-chef install\n\nOr to reference the Git version:\n\n cat >> Cheffile <<END_OF_CHEFFILE\n cookbook 'user',\n :git => 'git://github.com/fnichol/chef-user.git', :ref => 'v0.3.0'\n END_OF_CHEFFILE\n librarian-chef install\n\n### <a name=\"installation-kgc\"></a> Using knife-github-cookbooks\n\nThe [knife-github-cookbooks][kgc] gem is a plugin for *knife* that supports\ninstalling cookbooks directly from a GitHub repository. To install with the\nplugin:\n\n gem install knife-github-cookbooks\n cd chef-repo\n knife cookbook github install fnichol/chef-user/v0.3.0\n\n### <a name=\"installation-gitsubmodule\"></a> As a Git Submodule\n\nA common practice (which is getting dated) is to add cookbooks as Git\nsubmodules. This is accomplishes like so:\n\n cd chef-repo\n git submodule add git://github.com/fnichol/chef-user.git cookbooks/user\n git submodule init && git submodule update\n\n**Note:** the head of development will be linked here, not a tagged release.\n\n### <a name=\"installation-tarball\"></a> As a Tarball\n\nIf the cookbook needs to downloaded temporarily just to be uploaded to a Chef\nServer or Opscode Hosted Chef, then a tarball installation might fit the bill:\n\n cd chef-repo/cookbooks\n curl -Ls https://github.com/fnichol/chef-user/tarball/v0.3.0 | tar xfz - && \\\n mv fnichol-chef-user-* user\n\n## <a name=\"recipes\"></a> Recipes\n\n### <a name=\"recipes-default\"></a> default\n\nThis recipe is a no-op and does nothing.\n\n### <a name=\"recipes-data-bag\"></a> default\n\nProcesses a list of users with data drawn from a data bag. The default data bag\nis `users` and the list of user account to create on this node is set on\n`node['users']`.\n\n## <a name=\"attributes\"></a> Attributes\n\n### <a name=\"attributes-home-root\"></a> home_root\n\nThe default parent path of a user's home directory. Each resource can override\nthis value which varies by platform. Generally speaking, the default value is\n`\"/home\"`.\n\n### <a name=\"attributes-default-shell\"></a> default_shell\n\nThe default user shell given to a user. Each resource can override this value\nwhich varies by platform. Generally speaking, the default value is\n`\"/bin/bash\"`.\n\n### <a name=\"attributes-manage-home\"></a> manage_home\n\nWhether of not to manage the home directory of a user by default. Each resource\ncan override this value. The are 2 valid states:\n\n* `\"true\"`, `true`, or `\"yes\"`: will manage the user's home directory.\n* `\"false\"`, `false`, or `\"no\"`: will not manage the user's home directory.\n\nThe default is `true`.\n\n### <a name=\"attributes-create-user-group\"></a> create_user_group\n\nWhether or not to to create a group with the same name as the user by default.\nEach resource can override this value. The are 2 valid states:\n\n* `\"true\"`, `true`, or `\"yes\"`: will create a group for the user by default.\n* `\"false\"`, `false`, or `\"no\"`: will not create a group for the user by default.\n\nThe default is `true`.\n\n### <a name=\"attributes-ssh-keygen\"></a> ssh_keygen\n\nWhether or not to generate an SSH keypair for the user by default. Each\nresource can override this value. There are 2 valid states:\n\n* `\"true\"`, `true`, or `\"yes\"`: will generate an SSH keypair when the account\n is created.\n* `\"false\"`, `false`, or `\"no\"`: will not generate an SSH keypair when the account\n is created.\n\nThe default is `true`.\n\n### <a name=\"attributes-data-bag-name\"></a> data_bag_name\n\nThe data bag name containing a group of user account information. This is used\nby the `data_bag` recipe to use as a database of user accounts.\n\nThe default is `\"users\"`.\n\n### <a name=\"attributes-user-array-node-attr\"></a> user_array_node_attr\n\nThe node attributes containing an array of users to be managed. If a nested\nhash in the node's attributes is required, then use a `/` between subhashes.\nFor example, if the users' array is stored in `node['system']['accounts']`),\nthen set `node['user']['user_array_node_attr']` to `\"system/accounts\"`.\n\nThe default is `\"users\"`.\n\n## <a name=\"lwrps\"></a> Resources and Providers\n\n### <a name=\"lwrps-ua\"></a> user_account\n\n**Note:** in order to use the `password` attribute, you must have the\n[ruby-shadow gem][ruby-shadow_gem] installed. On Debian/Ubuntu you can get\nthis by installing the \"libshadow-ruby1.8\" package.\n\n### <a name=\"lwrps-ua-actions\"></a> Actions\n\n<table>\n <thead>\n <tr>\n <th>Action</th>\n <th>Description</th>\n <th>Default</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>create</td>\n <td>\n Create the user, its home directory, <code>.ssh/authorized_keys</code>,\n and <code>.ssh/{id_dsa,id_dsa.pub}</code>.\n </td>\n <td>Yes</td>\n </tr>\n <tr>\n <td>remove</td>\n <td>Remove the user account.</td>\n <td> </td>\n </tr>\n <tr>\n <td>modify</td>\n <td>Modiy the user account.</td>\n <td> </td>\n </tr>\n <tr>\n <td>manage</td>\n <td>Manage the user account.</td>\n <td> </td>\n </tr>\n <tr>\n <td>lock</td>\n <td>Lock the user's password.</td>\n <td> </td>\n </tr>\n <tr>\n <td>unlock</td>\n <td>Unlock the user's password.</td>\n <td> </td>\n </tr>\n </tbody>\n</table>\n\n### <a name=\"lwrps-ua-attributes\"></a> Attributes\n\n<table>\n <thead>\n <tr>\n <th>Attribute</th>\n <th>Description</th>\n <th>Default Value</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>username</td>\n <td><b>Name attribute:</b> The name of the user.</td>\n <td><code>nil</code></td>\n </tr>\n <tr>\n <td>comment</td>\n <td>Gecos/Comment field.</td>\n <td><code>nil</code></td>\n </tr>\n <tr>\n <td>uid</td>\n <td>The numeric user id.</td>\n <td><code>nil</code></td>\n </tr>\n <tr>\n <td>gid</td>\n <td>The primary group id.</td>\n <td><code>nil</code></td>\n </tr>\n <tr>\n <td>home</td>\n <td>Home directory location.</td>\n <td><code>\"#{node['user']['home_root']}/#{username}</code></td>\n </tr>\n <tr>\n <td>shell</td>\n <td>The login shell.</td>\n <td><code>node['user']['default_shell']</code></td>\n </tr>\n <tr>\n <td>password</td>\n <td>Shadow hash of password.</td>\n <td><code>nil</code></td>\n </tr>\n <tr>\n <td>system_user</td>\n <td>Whether or not to create a system user.</td>\n <td><code>false</code></td>\n </tr>\n <tr>\n <td>manage_home</td>\n <td>Whether or not to manage the home directory.</td>\n <td><code>true</code></td>\n </tr>\n <tr>\n <td>create_group</td>\n <td>\n Whether or not to to create a group with the same name as the user.\n </td>\n <td><code>node['user']['create_group']</code></td>\n </tr>\n <tr>\n <td>ssh_keys</td>\n <td>\n A <b>String</b> or <b>Array</b> of SSH public keys to populate the\n user's <code>.ssh/authorized_keys</code> file.\n </td>\n <td><code>[]</code></td>\n </tr>\n <tr>\n <td>ssh_keygen</td>\n <td>Whether or not to generate an SSH keypair for the user.</td>\n <td><code>node['user']['ssh_keygen']</code></td>\n </tr>\n </tbody>\n</table>\n\n#### <a name=\"lwrps-ua-examples\"></a> Examples\n\n##### Creating a User Account\n\n user_account 'hsolo' do\n comment 'Han Solo'\n ssh_keys ['3dc348d9af8027df7b9c...', '2154d3734d609eb5c452...']\n home '/opt/hoth/hsolo'\n end\n\n##### Locking a User Account\n\n user_account 'lando' do\n action :lock\n end\n\n##### Removing a User account\n\n user_account 'obiwan' do\n action :remove\n end\n\n## <a name=\"development\"></a> Development\n\n* Source hosted at [GitHub][repo]\n* Report issues/Questions/Feature requests on [GitHub Issues][issues]\n\nPull requests are very welcome! Make sure your patches are well tested.\nIdeally create a topic branch for every separate change you make.\n\n## <a name=\"license\"></a> License and Author\n\nAuthor:: [Fletcher Nichol][fnichol] (<fnichol@nichol.ca>) [](http://coderwall.com/fnichol)\n\nCopyright 2011, Fletcher Nichol\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n[chef_repo]: https://github.com/opscode/chef-repo\n[cheffile]: https://github.com/applicationsonline/librarian/blob/master/lib/librarian/chef/templates/Cheffile\n[kgc]: https://github.com/websterclay/knife-github-cookbooks#readme\n[librarian]: https://github.com/applicationsonline/librarian#readme\n[ruby-shadow_gem]: https://rubygems.org/gems/ruby-shadow\n\n[repo]: https://github.com/fnichol/chef-user\n[issues]: https://github.com/fnichol/chef-user/issues\n",
|
5
|
+
"maintainer": "Fletcher Nichol",
|
6
|
+
"maintainer_email": "fnichol@nichol.ca",
|
7
|
+
"license": "Apache 2.0",
|
8
|
+
"platforms": {
|
9
|
+
"ubuntu": ">= 0.0.0",
|
10
|
+
"debian": ">= 0.0.0",
|
11
|
+
"mac_os_x": ">= 0.0.0",
|
12
|
+
"suse": ">= 0.0.0"
|
13
|
+
},
|
14
|
+
"dependencies": {
|
15
|
+
},
|
16
|
+
"recommendations": {
|
17
|
+
},
|
18
|
+
"suggestions": {
|
19
|
+
},
|
20
|
+
"conflicting": {
|
21
|
+
},
|
22
|
+
"providing": {
|
23
|
+
},
|
24
|
+
"replacing": {
|
25
|
+
},
|
26
|
+
"attributes": {
|
27
|
+
},
|
28
|
+
"groupings": {
|
29
|
+
},
|
30
|
+
"recipes": {
|
31
|
+
"user": "This recipe is a no-op and does nothing.",
|
32
|
+
"user::data_bag": "Processes a list of users with data drawn from a data bag."
|
33
|
+
},
|
34
|
+
"version": "0.3.0"
|
35
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
maintainer "Fletcher Nichol"
|
2
|
+
maintainer_email "fnichol@nichol.ca"
|
3
|
+
license "Apache 2.0"
|
4
|
+
description "A convenient Chef LWRP to manage user accounts and SSH keys (this is not the opscode users cookbook)"
|
5
|
+
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
6
|
+
version "0.3.0"
|
7
|
+
|
8
|
+
supports "ubuntu"
|
9
|
+
supports "debian"
|
10
|
+
supports "mac_os_x"
|
11
|
+
supports "suse"
|
12
|
+
|
13
|
+
recipe "user", "This recipe is a no-op and does nothing."
|
14
|
+
recipe "user::data_bag", "Processes a list of users with data drawn from a data bag."
|
@@ -0,0 +1,173 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: user
|
3
|
+
# Provider:: account
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2011, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
def load_current_resource
|
23
|
+
@my_home = new_resource.home ||
|
24
|
+
"#{node['user']['home_root']}/#{new_resource.username}"
|
25
|
+
@my_shell = new_resource.shell || node['user']['default_shell']
|
26
|
+
@manage_home = bool(new_resource.manage_home, node['user']['manage_home'])
|
27
|
+
@create_group = bool(new_resource.create_group, node['user']['create_group'])
|
28
|
+
@ssh_keygen = bool(new_resource.ssh_keygen, node['user']['ssh_keygen'])
|
29
|
+
end
|
30
|
+
|
31
|
+
action :create do
|
32
|
+
user_resource :create
|
33
|
+
dir_resource :create
|
34
|
+
authorized_keys_resource :create
|
35
|
+
keygen_resource :create
|
36
|
+
end
|
37
|
+
|
38
|
+
action :remove do
|
39
|
+
keygen_resource :delete
|
40
|
+
authorized_keys_resource :delete
|
41
|
+
dir_resource :delete
|
42
|
+
user_resource :remove
|
43
|
+
end
|
44
|
+
|
45
|
+
action :modify do
|
46
|
+
user_resource :modify
|
47
|
+
dir_resource :create
|
48
|
+
authorized_keys_resource :create
|
49
|
+
keygen_resource :create
|
50
|
+
end
|
51
|
+
|
52
|
+
action :manage do
|
53
|
+
user_resource :manage
|
54
|
+
dir_resource :create
|
55
|
+
authorized_keys_resource :create
|
56
|
+
keygen_resource :create
|
57
|
+
end
|
58
|
+
|
59
|
+
action :lock do
|
60
|
+
user_resource :lock
|
61
|
+
dir_resource :create
|
62
|
+
authorized_keys_resource :create
|
63
|
+
keygen_resource :create
|
64
|
+
end
|
65
|
+
|
66
|
+
action :unlock do
|
67
|
+
user_resource :unlock
|
68
|
+
dir_resource :create
|
69
|
+
authorized_keys_resource :create
|
70
|
+
keygen_resource :create
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def bool(resource_val, default_val)
|
76
|
+
if resource_val.nil?
|
77
|
+
normalize_bool(default_val)
|
78
|
+
else
|
79
|
+
normalize_bool(resource_val)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def normalize_bool(val)
|
84
|
+
case val
|
85
|
+
when 'no','false',false then false
|
86
|
+
else true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def user_resource(exec_action)
|
91
|
+
# avoid variable scoping issues in resource block
|
92
|
+
my_home, my_shell, manage_home = @my_home, @my_shell, @manage_home
|
93
|
+
|
94
|
+
r = user new_resource.username do
|
95
|
+
comment new_resource.comment if new_resource.comment
|
96
|
+
uid new_resource.uid if new_resource.uid
|
97
|
+
gid new_resource.gid if new_resource.gid
|
98
|
+
home my_home if my_home
|
99
|
+
shell my_shell if my_shell
|
100
|
+
password new_resource.password if new_resource.password
|
101
|
+
system new_resource.system_user
|
102
|
+
supports :manage_home => manage_home
|
103
|
+
action :nothing
|
104
|
+
end
|
105
|
+
r.run_action(exec_action)
|
106
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
107
|
+
|
108
|
+
# fixes CHEF-1699
|
109
|
+
Etc.endgrent
|
110
|
+
end
|
111
|
+
|
112
|
+
def dir_resource(exec_action)
|
113
|
+
["#{@my_home}/.ssh", @my_home].each do |dir|
|
114
|
+
r = directory dir do
|
115
|
+
owner new_resource.username
|
116
|
+
group Etc.getpwnam(new_resource.username).gid
|
117
|
+
mode dir =~ %r{/\.ssh$} ? '0700' : '2755'
|
118
|
+
recursive true
|
119
|
+
action :nothing
|
120
|
+
end
|
121
|
+
r.run_action(exec_action)
|
122
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def authorized_keys_resource(exec_action)
|
127
|
+
# avoid variable scoping issues in resource block
|
128
|
+
ssh_keys = Array(new_resource.ssh_keys)
|
129
|
+
|
130
|
+
r = template "#{@my_home}/.ssh/authorized_keys" do
|
131
|
+
cookbook 'user'
|
132
|
+
source 'authorized_keys.erb'
|
133
|
+
owner new_resource.username
|
134
|
+
group Etc.getpwnam(new_resource.username).gid
|
135
|
+
mode '0600'
|
136
|
+
variables :user => new_resource.username,
|
137
|
+
:ssh_keys => ssh_keys
|
138
|
+
action :nothing
|
139
|
+
end
|
140
|
+
r.run_action(exec_action)
|
141
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
142
|
+
end
|
143
|
+
|
144
|
+
def keygen_resource(exec_action)
|
145
|
+
# avoid variable scoping issues in resource block
|
146
|
+
fqdn, my_home = node['fqdn'], @my_home
|
147
|
+
|
148
|
+
e = execute "create ssh keypair for #{new_resource.username}" do
|
149
|
+
cwd my_home
|
150
|
+
user new_resource.username
|
151
|
+
command <<-KEYGEN.gsub(/^ +/, '')
|
152
|
+
ssh-keygen -t dsa -f #{my_home}/.ssh/id_dsa -N '' \
|
153
|
+
-C '#{new_resource.username}@#{fqdn}-#{Time.now.strftime('%FT%T%z')}'
|
154
|
+
chmod 0600 #{my_home}/.ssh/id_dsa
|
155
|
+
chmod 0644 #{my_home}/.ssh/id_dsa.pub
|
156
|
+
KEYGEN
|
157
|
+
action :nothing
|
158
|
+
|
159
|
+
creates "#{my_home}/.ssh/id_dsa"
|
160
|
+
end
|
161
|
+
e.run_action(:run) if @ssh_keygen && exec_action == :create
|
162
|
+
new_resource.updated_by_last_action(true) if e.updated_by_last_action?
|
163
|
+
|
164
|
+
if exec_action == :delete then
|
165
|
+
["#{@my_home}/.ssh/id_dsa", "#{@my_home}/.ssh/id_dsa.pub"].each do |keyfile|
|
166
|
+
r = file keyfile do
|
167
|
+
backup false
|
168
|
+
action :delete
|
169
|
+
end
|
170
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: user
|
3
|
+
# Recipe:: data_bag
|
4
|
+
#
|
5
|
+
# Copyright 2011, Fletcher Nichol
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
bag = node['user']['data_bag_name']
|
21
|
+
|
22
|
+
# Fetch the user array from the node's attribute hash. If a subhash is
|
23
|
+
# desired (ex. node['base']['user_accounts']), then set:
|
24
|
+
#
|
25
|
+
# node['user']['user_array_node_attr'] = "base/user_accounts"
|
26
|
+
user_array = node
|
27
|
+
node['user']['user_array_node_attr'].split("/").each do |hash_key|
|
28
|
+
user_array = user_array.send(:[], hash_key)
|
29
|
+
end
|
30
|
+
|
31
|
+
# only manage the subset of users defined
|
32
|
+
Array(user_array).each do |i|
|
33
|
+
u = data_bag_item(bag, i.gsub(/[.]/, '-'))
|
34
|
+
username = u['username'] || u['id']
|
35
|
+
|
36
|
+
user_account username do
|
37
|
+
%w{comment uid gid home shell password system_user manage_home create_group
|
38
|
+
ssh_keys ssh_keygen}.each do |attr|
|
39
|
+
send(attr, u[attr]) if u[attr]
|
40
|
+
end
|
41
|
+
action u['action'].to_sym if u['action']
|
42
|
+
end
|
43
|
+
|
44
|
+
unless u['groups'].nil?
|
45
|
+
u['groups'].each do |groupname|
|
46
|
+
group groupname do
|
47
|
+
members username
|
48
|
+
append true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: user
|
3
|
+
# Recipe:: default
|
4
|
+
#
|
5
|
+
# Copyright 2011, Fletcher Nichol
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: user
|
3
|
+
# Resource:: account
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2011, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
actions :create, :remove, :modify, :manage, :lock, :unlock
|
23
|
+
|
24
|
+
attribute :username, :kind_of => String, :name_attribute => true
|
25
|
+
attribute :comment, :kind_of => String
|
26
|
+
attribute :uid, :kind_of => [String,Integer]
|
27
|
+
attribute :gid, :kind_of => [String,Integer]
|
28
|
+
attribute :home, :kind_of => String
|
29
|
+
attribute :shell, :kind_of => String
|
30
|
+
attribute :password, :kind_of => String
|
31
|
+
attribute :system_user, :default => false
|
32
|
+
attribute :manage_home, :default => nil
|
33
|
+
attribute :create_group, :default => nil
|
34
|
+
attribute :ssh_keys, :kind_of => [Array,String], :default => []
|
35
|
+
attribute :ssh_keygen, :default => nil
|
36
|
+
|
37
|
+
def initialize(*args)
|
38
|
+
super
|
39
|
+
@action = :create
|
40
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
{
|
2
|
+
"id": "michael",
|
3
|
+
"username": "michael",
|
4
|
+
"comment": "Michael Schmidt",
|
5
|
+
"ssh_keys": [
|
6
|
+
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvFapuevZeHFpFn438XMjvEQYd0wt7+tzUdAkMiSd007Tx1h79Xm9ZziDDUe4W6meinVOq93MAS/ER27hoVWGo2H/vn/Cz5M8xr2j5rQODnrF3RmfrJTbZAWaDN0JTq2lFjmCHhZJNhr+VQP1uw4z2ofMBP6MLybnLmm9ukzxFYZqCCyfEEUTCMA9SWywtTpGQp8VLM4INCxzBSCuyt3SO6PBvJSo4HoKg/sLvmRwpCVZth48PI0EUbJ72wp88Cw3bv8CLce2TOkLMwkE6NRN55w2aOyqP1G3vixHa6YcVaLlkQhJoJsBwE3rX5603y2KjOhMomqHfXxXn/3GKTWlsQ=="
|
7
|
+
]
|
8
|
+
}
|
9
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"id": "bugroger",
|
3
|
+
"username": "bugroger",
|
4
|
+
"comment": "Michael Schmidt",
|
5
|
+
"admin" : true,
|
6
|
+
"ssh_keys": [
|
7
|
+
"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvFapuevZeHFpFn438XMjvEQYd0wt7+tzUdAkMiSd007Tx1h79Xm9ZziDDUe4W6meinVOq93MAS/ER27hoVWGo2H/vn/Cz5M8xr2j5rQODnrF3RmfrJTbZAWaDN0JTq2lFjmCHhZJNhr+VQP1uw4z2ofMBP6MLybnLmm9ukzxFYZqCCyfEEUTCMA9SWywtTpGQp8VLM4INCxzBSCuyt3SO6PBvJSo4HoKg/sLvmRwpCVZth48PI0EUbJ72wp88Cw3bv8CLce2TOkLMwkE6NRN55w2aOyqP1G3vixHa6YcVaLlkQhJoJsBwE3rX5603y2KjOhMomqHfXxXn/3GKTWlsQ=="
|
8
|
+
]
|
9
|
+
}
|
10
|
+
|
@@ -1 +1 @@
|
|
1
|
-
{"run_list":[]}
|
1
|
+
{"run_list":["recipe[user::data_bag]", "recipe[blinkenstein]"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
depends "user"
|
data/lib/blinkenstein/version.rb
CHANGED
metadata
CHANGED
@@ -2,47 +2,15 @@
|
|
2
2
|
name: blinkenstein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michael Schmidt
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rspec
|
16
|
-
type: :development
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ! '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0'
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: knife-solo
|
32
|
-
type: :development
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
|
-
requirements:
|
36
|
-
- - ! '>='
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: '0'
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
14
|
- !ruby/object:Gem::Dependency
|
47
15
|
name: celluloid
|
48
16
|
type: :runtime
|
@@ -117,18 +85,37 @@ extra_rdoc_files: []
|
|
117
85
|
files:
|
118
86
|
- .chef/knife.rb
|
119
87
|
- .gitignore
|
88
|
+
- .librarian/chef/config
|
89
|
+
- Cheffile
|
90
|
+
- Cheffile.lock
|
120
91
|
- Gemfile
|
121
92
|
- LICENSE.txt
|
122
93
|
- README.md
|
123
94
|
- Rakefile
|
124
95
|
- bin/blinkenstein
|
125
96
|
- blinkenstein.gemspec
|
126
|
-
- chef/cookbooks/.
|
97
|
+
- chef/cookbooks/user/.gitignore
|
98
|
+
- chef/cookbooks/user/.travis.yml
|
99
|
+
- chef/cookbooks/user/CHANGELOG.md
|
100
|
+
- chef/cookbooks/user/README.md
|
101
|
+
- chef/cookbooks/user/Rakefile
|
102
|
+
- chef/cookbooks/user/attributes/default.rb
|
103
|
+
- chef/cookbooks/user/metadata.json
|
104
|
+
- chef/cookbooks/user/metadata.rb
|
105
|
+
- chef/cookbooks/user/providers/account.rb
|
106
|
+
- chef/cookbooks/user/recipes/data_bag.rb
|
107
|
+
- chef/cookbooks/user/recipes/default.rb
|
108
|
+
- chef/cookbooks/user/resources/account.rb
|
109
|
+
- chef/cookbooks/user/templates/default/authorized_keys.erb
|
127
110
|
- chef/data_bags/.gitkeep
|
111
|
+
- chef/data_bags/users/bugroger.json
|
112
|
+
- chef/data_bags/users/michael.json
|
128
113
|
- chef/nodes/.gitkeep
|
129
114
|
- chef/nodes/192.168.1.110.json
|
130
115
|
- chef/roles/.gitkeep
|
131
116
|
- chef/site-cookbooks/.gitkeep
|
117
|
+
- chef/site-cookbooks/blinkenstein/metadata.rb
|
118
|
+
- chef/site-cookbooks/blinkenstein/recipes/default.rb
|
132
119
|
- chef/solo.rb
|
133
120
|
- lib/blinkenstein.rb
|
134
121
|
- lib/blinkenstein/blink.rb
|
data/chef/cookbooks/.gitkeep
DELETED
File without changes
|