from-scratch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.chef/knife.rb +6 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Berksfile +17 -0
- data/Berksfile.lock +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/Thorfile +5 -0
- data/bin/scratchify +6 -0
- data/chefignore +101 -0
- data/cookbooks/chef_gem/CHANGELOG.md +24 -0
- data/cookbooks/chef_gem/README.md +38 -0
- data/cookbooks/chef_gem/libraries/chef_gem.rb +72 -0
- data/cookbooks/chef_gem/metadata.json +29 -0
- data/cookbooks/chef_gem/recipes/default.rb +0 -0
- data/cookbooks/java/.gitignore +21 -0
- data/cookbooks/java/.kitchen.docker.yml +15 -0
- data/cookbooks/java/.kitchen.yml +126 -0
- data/cookbooks/java/.travis.yml +6 -0
- data/cookbooks/java/Berksfile +10 -0
- data/cookbooks/java/CHANGELOG.md +398 -0
- data/cookbooks/java/CONTRIBUTING.md +12 -0
- data/cookbooks/java/Gemfile +15 -0
- data/cookbooks/java/ISSUES.md +43 -0
- data/cookbooks/java/LICENSE +201 -0
- data/cookbooks/java/README.md +402 -0
- data/cookbooks/java/Rakefile +60 -0
- data/cookbooks/java/TESTING.md +41 -0
- data/cookbooks/java/attributes/default.rb +146 -0
- data/cookbooks/java/libraries/helpers.rb +120 -0
- data/cookbooks/java/libraries/matchers.rb +5 -0
- data/cookbooks/java/metadata.json +69 -0
- data/cookbooks/java/providers/alternatives.rb +94 -0
- data/cookbooks/java/providers/ark.rb +255 -0
- data/cookbooks/java/recipes/default.rb +22 -0
- data/cookbooks/java/recipes/default_java_symlink.rb +19 -0
- data/cookbooks/java/recipes/homebrew.rb +3 -0
- data/cookbooks/java/recipes/ibm.rb +76 -0
- data/cookbooks/java/recipes/ibm_tar.rb +70 -0
- data/cookbooks/java/recipes/openjdk.rb +74 -0
- data/cookbooks/java/recipes/oracle.rb +74 -0
- data/cookbooks/java/recipes/oracle_i386.rb +73 -0
- data/cookbooks/java/recipes/oracle_jce.rb +75 -0
- data/cookbooks/java/recipes/oracle_rpm.rb +60 -0
- data/cookbooks/java/recipes/purge_packages.rb +20 -0
- data/cookbooks/java/recipes/set_attributes_from_version.rb +55 -0
- data/cookbooks/java/recipes/set_java_home.rb +44 -0
- data/cookbooks/java/recipes/windows.rb +82 -0
- data/cookbooks/java/resources/alternatives.rb +30 -0
- data/cookbooks/java/resources/ark.rb +58 -0
- data/cookbooks/java/templates/default/ibm_jdk.installer.properties.erb +3 -0
- data/cookbooks/java/templates/default/oracle.jinfo.erb +6 -0
- data/cookbooks/rvm/.foodcritic +1 -0
- data/cookbooks/rvm/.gitignore +7 -0
- data/cookbooks/rvm/.kitchen.yml +66 -0
- data/cookbooks/rvm/.travis.yml +9 -0
- data/cookbooks/rvm/Berksfile +10 -0
- data/cookbooks/rvm/CHANGELOG.md +253 -0
- data/cookbooks/rvm/CODE_OF_CONDUCT.md +12 -0
- data/cookbooks/rvm/CONTRIBUTING.md +26 -0
- data/cookbooks/rvm/Gemfile +20 -0
- data/cookbooks/rvm/Guardfile +12 -0
- data/cookbooks/rvm/README.md +1459 -0
- data/cookbooks/rvm/Rakefile +18 -0
- data/cookbooks/rvm/attributes/.gitkeep +0 -0
- data/cookbooks/rvm/attributes/default.rb +68 -0
- data/cookbooks/rvm/attributes/gem_package.rb +23 -0
- data/cookbooks/rvm/attributes/vagrant.rb +23 -0
- data/cookbooks/rvm/libraries/chef_rvm_environment_helpers.rb +55 -0
- data/cookbooks/rvm/libraries/chef_rvm_gemset_helpers.rb +67 -0
- data/cookbooks/rvm/libraries/chef_rvm_recipe_helpers.rb +80 -0
- data/cookbooks/rvm/libraries/chef_rvm_ruby_helpers.rb +95 -0
- data/cookbooks/rvm/libraries/chef_rvm_set_helpers.rb +16 -0
- data/cookbooks/rvm/libraries/chef_rvm_shell_helpers.rb +57 -0
- data/cookbooks/rvm/libraries/chef_rvm_string_cache.rb +104 -0
- data/cookbooks/rvm/libraries/chef_rvm_string_helpers.rb +61 -0
- data/cookbooks/rvm/libraries/chef_rvm_version_helpers.rb +45 -0
- data/cookbooks/rvm/libraries/gem_package_monkeypatch.rb +34 -0
- data/cookbooks/rvm/libraries/provider_rvm_installation.rb +185 -0
- data/cookbooks/rvm/libraries/resource_rvm_installation.rb +103 -0
- data/cookbooks/rvm/libraries/rvm_chef_user_environment.rb +55 -0
- data/cookbooks/rvm/libraries/rvm_rubygems_package.rb +189 -0
- data/cookbooks/rvm/libraries/rvm_shell_chef_wrapper.rb +99 -0
- data/cookbooks/rvm/metadata.json +51 -0
- data/cookbooks/rvm/providers/default_ruby.rb +63 -0
- data/cookbooks/rvm/providers/environment.rb +78 -0
- data/cookbooks/rvm/providers/gemset.rb +118 -0
- data/cookbooks/rvm/providers/global_gem.rb +97 -0
- data/cookbooks/rvm/providers/ruby.rb +178 -0
- data/cookbooks/rvm/providers/shell.rb +121 -0
- data/cookbooks/rvm/providers/wrapper.rb +73 -0
- data/cookbooks/rvm/recipes/.gitkeep +0 -0
- data/cookbooks/rvm/recipes/default.rb +40 -0
- data/cookbooks/rvm/recipes/gem_package.rb +33 -0
- data/cookbooks/rvm/recipes/system.rb +37 -0
- data/cookbooks/rvm/recipes/system_install.rb +42 -0
- data/cookbooks/rvm/recipes/user.rb +43 -0
- data/cookbooks/rvm/recipes/user_install.rb +58 -0
- data/cookbooks/rvm/recipes/vagrant.rb +37 -0
- data/cookbooks/rvm/resources/default_ruby.rb +31 -0
- data/cookbooks/rvm/resources/environment.rb +31 -0
- data/cookbooks/rvm/resources/gem.rb +37 -0
- data/cookbooks/rvm/resources/gemset.rb +32 -0
- data/cookbooks/rvm/resources/global_gem.rb +34 -0
- data/cookbooks/rvm/resources/ruby.rb +32 -0
- data/cookbooks/rvm/resources/shell.rb +41 -0
- data/cookbooks/rvm/resources/wrapper.rb +34 -0
- data/cookbooks/rvm/templates/default/rvmrc.erb +14 -0
- data/cookbooks/rvm/templates/default/vagrant-chef-client-wrapper.erb +23 -0
- data/cookbooks/rvm/templates/default/vagrant-chef-solo-wrapper.erb +23 -0
- data/cookbooks/rvm/test/integration/data_bags/users/virgil1.json +4 -0
- data/cookbooks/rvm/test/integration/data_bags/users/virgil2.json +4 -0
- data/cookbooks/rvm/test/integration/data_bags/users/wigglebottom.json +3 -0
- data/cookbooks/rvm/test/integration/installs/bats/version_pinning.bats +13 -0
- data/cookbooks/rvm/test/integration/rubies/bats/_common.bash +16 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_1.9.3.bats +9 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_jruby.bats +12 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_patch_support.bats +19 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_ree.bats +9 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_rubygems_version_support.bats +15 -0
- data/cookbooks/rvm/test/integration/stock_system_and_user/bats/system.bats +45 -0
- data/cookbooks/rvm/test/unit/libraries/provider_rvm_installation_spec.rb +220 -0
- data/cookbooks/rvm/test/unit/libraries/resource_rvm_installation_spec.rb +139 -0
- data/cookbooks/rvm/test/unit/spec_helper.rb +23 -0
- data/cookbooks/scratchify/.chef/knife.rb +9 -0
- data/cookbooks/scratchify/Berksfile +16 -0
- data/cookbooks/scratchify/Berksfile.lock +19 -0
- data/cookbooks/scratchify/LICENSE.txt +21 -0
- data/cookbooks/scratchify/README.md +41 -0
- data/cookbooks/scratchify/Thorfile +5 -0
- data/cookbooks/scratchify/bin/console +14 -0
- data/cookbooks/scratchify/bin/scratchify +6 -0
- data/cookbooks/scratchify/bin/setup +7 -0
- data/cookbooks/scratchify/chefignore +101 -0
- data/cookbooks/scratchify/data_bags/users/deploy.json +6 -0
- data/cookbooks/scratchify/environments/.gitkeep +0 -0
- data/cookbooks/scratchify/from-scratch.gemspec +36 -0
- data/cookbooks/scratchify/lib/from/scratch.rb +31 -0
- data/cookbooks/scratchify/lib/from/scratch/interviewer.rb +35 -0
- data/cookbooks/scratchify/lib/from/scratch/version.rb +3 -0
- data/cookbooks/scratchify/metadata.json +36 -0
- data/cookbooks/scratchify/nodes/normfood.ru.json +75 -0
- data/cookbooks/scratchify/recipes/default.rb +0 -0
- data/cookbooks/scratchify/roles/.gitkeep +0 -0
- data/cookbooks/scratchify/spec/from/scratch_spec.rb +11 -0
- data/cookbooks/scratchify/spec/spec_helper.rb +2 -0
- data/cookbooks/user/.gitignore +5 -0
- data/cookbooks/user/.kitchen.yml +46 -0
- data/cookbooks/user/.travis.yml +4 -0
- data/cookbooks/user/Berksfile +7 -0
- data/cookbooks/user/CHANGELOG.md +101 -0
- data/cookbooks/user/Gemfile +14 -0
- data/cookbooks/user/README.md +447 -0
- data/cookbooks/user/Rakefile +21 -0
- data/cookbooks/user/attributes/default.rb +50 -0
- data/cookbooks/user/libraries/matchers.rb +26 -0
- data/cookbooks/user/metadata.json +46 -0
- data/cookbooks/user/providers/account.rb +212 -0
- data/cookbooks/user/recipes/data_bag.rb +59 -0
- data/cookbooks/user/recipes/default.rb +18 -0
- data/cookbooks/user/resources/account.rb +41 -0
- data/cookbooks/user/templates/default/authorized_keys.erb +7 -0
- data/from-scratch.gemspec +33 -0
- data/lib/from-scratch.rb +25 -0
- data/lib/from-scratch/version.rb +3 -0
- data/metadata.rb +15 -0
- data/recipes/default.rb +0 -0
- data/templates/node.json.erb +31 -0
- data/templates/user.json.erb +6 -0
- metadata +330 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'foodcritic'
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.test_files = FileList['test/unit/**/*_spec.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
FoodCritic::Rake::LintTask.new do |t|
|
11
|
+
t.options = { :tags => ['~FC048'], :fail_tags => ['any'] }
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'kitchen/rake_tasks'
|
16
|
+
Kitchen::RakeTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => [:foodcritic, :test]
|
@@ -0,0 +1,50 @@
|
|
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
|
+
when 'omnios'
|
33
|
+
default['user']['home_root'] = "/export/home"
|
34
|
+
default['user']['default_shell'] = "/bin/bash"
|
35
|
+
else
|
36
|
+
default['user']['home_root'] = "/home"
|
37
|
+
default['user']['default_shell'] = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
default['user']['home_dir_mode'] = '2755'
|
41
|
+
|
42
|
+
default['user']['manage_home'] = "true"
|
43
|
+
default['user']['create_user_group'] = "true"
|
44
|
+
default['user']['ssh_keygen'] = "true"
|
45
|
+
default['user']['non_unique'] = "false"
|
46
|
+
|
47
|
+
default['user']['data_bag_name'] = "users"
|
48
|
+
default['user']['user_array_node_attr'] = "users"
|
49
|
+
|
50
|
+
default[default['user']['user_array_node_attr']] = []
|
@@ -0,0 +1,26 @@
|
|
1
|
+
if defined?(ChefSpec)
|
2
|
+
if Gem::Version.new(ChefSpec::VERSION) < Gem::Version.new('4.1.0')
|
3
|
+
ChefSpec::Runner.define_runner_method :user_account
|
4
|
+
else
|
5
|
+
ChefSpec.define_matcher :user_account
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_user_account(user)
|
9
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user_account, :create, user)
|
10
|
+
end
|
11
|
+
def remove_user_account(user)
|
12
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user_account, :remove, user)
|
13
|
+
end
|
14
|
+
def modify_user_account(user)
|
15
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user_account, :modify, user)
|
16
|
+
end
|
17
|
+
def manage_user_account(user)
|
18
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user_account, :manage, user)
|
19
|
+
end
|
20
|
+
def lock_user_account(user)
|
21
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user_account, :lock, user)
|
22
|
+
end
|
23
|
+
def unlock_user_account(user)
|
24
|
+
ChefSpec::Matchers::ResourceMatcher.new(:user_account, :unlock, user)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
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> User Chef Cookbook\n\n[![Build Status](https://secure.travis-ci.org/fnichol/chef-user.png?branch=master)](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* Website: http://fnichol.github.io/chef-user/\n* Opscode Community Site: http://community.opscode.com/cookbooks/user\n* Source Code: https://github.com/fnichol/chef-user\n\n## <a name=\"usage\"></a> Usage\n\nSimply include this cookbook as a dependency in `metadata.rb` and the `user_account`\nresource will be available. Example:\n\n # In your_cookbook/metadata.rb\n depends 'user'\n\n # In your_cookbook/recipes/default.rb\n user_account 'hsolo' do\n ssh_keygen true\n end\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 \"groups\" : [\"admin\", \"www-data\"],\n \"ssh_keys\" : [\"123...\", \"456...\"]\n }\n\nor a user to be removed:\n\n {\n \"id\" : \"lando\",\n \"action\" : \"remove\"\n }\n\nIf you have a username containing a period, use a dash in the data bag item\nand set a `username` attribute:\n\n {\n \"id\" : \"luke-skywalker\",\n \"username\" : \"luke.skywalker\",\n \"action\" : [\"create\", \"lock\"]\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', 'lando', 'luke.skywalker']\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 Community Site\n\nTo install this cookbook from the Community Site, use the *knife* command:\n\n knife cookbook site install user\n\n### <a name=\"installation-berkshelf\"></a> Using Berkshelf\n\n[Berkshelf][berkshelf] is a cookbook dependency manager and development\nworkflow assistant. To install Berkshelf:\n\n cd chef-repo\n gem install berkshelf\n berks init\n\nTo use the Community Site version:\n\n echo \"cookbook 'user'\" >> Berksfile\n berks install\n\nOr to reference the Git version:\n\n repo=\"fnichol/chef-user\"\n latest_release=$(curl -s https://api.github.com/repos/$repo/git/refs/tags \\\n | ruby -rjson -e '\n j = JSON.parse(STDIN.read);\n puts j.map { |t| t[\"ref\"].split(\"/\").last }.sort.last\n ')\n cat >> Berksfile <<END_OF_BERKSFILE\n cookbook 'user',\n :git => 'git://github.com/$repo.git', :branch => '$latest_release'\n END_OF_BERKSFILE\n berks install\n\n### <a name=\"installation-librarian\"></a> Using Librarian-Chef\n\n[Librarian-Chef][librarian] is a bundler for your Chef cookbooks.\nTo install Librarian-Chef:\n\n cd chef-repo\n gem install librarian\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 repo=\"fnichol/chef-user\"\n latest_release=$(curl -s https://api.github.com/repos/$repo/git/refs/tags \\\n | ruby -rjson -e '\n j = JSON.parse(STDIN.read);\n puts j.map { |t| t[\"ref\"].split(\"/\").last }.sort.last\n ')\n cat >> Cheffile <<END_OF_CHEFFILE\n cookbook 'user',\n :git => 'git://github.com/$repo.git', :ref => '$latest_release'\n END_OF_CHEFFILE\n librarian-chef install\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> data_bag\n\nProcesses a list of users with data drawn from a data bag. The default data bag\nis `users` and the list of user accounts 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-home-dir-mode\"></a> home_dir_mode\n\nThe default Unix permissions applied to a user's home directory.\n\nThe default is `\"2755\"`.\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-non-unique\"></a> non_unique\n\nWhether of not to allow the creation of a user account with a duplicate UID.\nEach resource can override this value. The are 2 valid states:\n\n* `\"true\"`, `true`, or `\"yes\"`: will allow duplicate UIDs.\n* `\"false\"`, `false`, or `\"no\"`: will not allow duplicate UIDs.\n\nThe default is `false`.\n\n### <a name=\"attributes-create-user-group\"></a> create_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_rsa,id_rsa.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>Modify 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>groups</td>\n <td>Array of other groups this user should be a member of.</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>non_unique</td>\n <td>Whether or not to allow the creation of a user account with a duplicate UID.</td>\n <td><code>false</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 <tr>\n <td>groups</td>\n <td>An Array of groups to which to add the user.</td>\n <td><code>[]</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##### Creating and Locking a User Account\n\n user_account 'lando' do\n action [:create, :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>) [![endorse](http://api.coderwall.com/fnichol/endorsecount.png)](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[berkshelf]: http://berkshelf.com/\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
|
+
"omnios": ">= 0.0.0"
|
14
|
+
},
|
15
|
+
"dependencies": {
|
16
|
+
|
17
|
+
},
|
18
|
+
"recommendations": {
|
19
|
+
|
20
|
+
},
|
21
|
+
"suggestions": {
|
22
|
+
|
23
|
+
},
|
24
|
+
"conflicting": {
|
25
|
+
|
26
|
+
},
|
27
|
+
"providing": {
|
28
|
+
|
29
|
+
},
|
30
|
+
"replacing": {
|
31
|
+
|
32
|
+
},
|
33
|
+
"attributes": {
|
34
|
+
|
35
|
+
},
|
36
|
+
"groupings": {
|
37
|
+
|
38
|
+
},
|
39
|
+
"recipes": {
|
40
|
+
"user": "This recipe is a no-op and does nothing.",
|
41
|
+
"user::data_bag": "Processes a list of users with data drawn from a data bag."
|
42
|
+
},
|
43
|
+
"version": "0.4.2",
|
44
|
+
"source_url": "",
|
45
|
+
"issues_url": ""
|
46
|
+
}
|
@@ -0,0 +1,212 @@
|
|
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
|
+
require "chef/resource"
|
22
|
+
|
23
|
+
use_inline_resources
|
24
|
+
|
25
|
+
def whyrun_supported?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_current_resource
|
30
|
+
@my_home = new_resource.home ||
|
31
|
+
"#{node['user']['home_root']}/#{new_resource.username}"
|
32
|
+
@my_shell = new_resource.shell || node['user']['default_shell']
|
33
|
+
@manage_home = bool(new_resource.manage_home, node['user']['manage_home'])
|
34
|
+
@non_unique = bool(new_resource.non_unique, node['user']['non_unique'])
|
35
|
+
@create_group = bool(new_resource.create_group, node['user']['create_group'])
|
36
|
+
@ssh_keygen = bool(new_resource.ssh_keygen, node['user']['ssh_keygen'])
|
37
|
+
end
|
38
|
+
|
39
|
+
action :create do # ~FC017: LWRP does not notify when updated
|
40
|
+
user_resource :create
|
41
|
+
home_dir_resource :create
|
42
|
+
authorized_keys_resource :create
|
43
|
+
keygen_resource :create
|
44
|
+
end
|
45
|
+
|
46
|
+
action :remove do # ~FC017: LWRP does not notify when updated
|
47
|
+
# Removing a user will also remove all the other file based resources.
|
48
|
+
# By only removing the user it will make this action idempotent.
|
49
|
+
user_resource :remove
|
50
|
+
end
|
51
|
+
|
52
|
+
action :modify do # ~FC017: LWRP does not notify when updated
|
53
|
+
user_resource :modify
|
54
|
+
home_dir_resource :create
|
55
|
+
authorized_keys_resource :create
|
56
|
+
keygen_resource :create
|
57
|
+
end
|
58
|
+
|
59
|
+
action :manage do # ~FC017: LWRP does not notify when updated
|
60
|
+
user_resource :manage
|
61
|
+
home_dir_resource :create
|
62
|
+
authorized_keys_resource :create
|
63
|
+
keygen_resource :create
|
64
|
+
end
|
65
|
+
|
66
|
+
action :lock do # ~FC017: LWRP does not notify when updated
|
67
|
+
user_resource :lock
|
68
|
+
home_dir_resource :create
|
69
|
+
authorized_keys_resource :create
|
70
|
+
keygen_resource :create
|
71
|
+
end
|
72
|
+
|
73
|
+
action :unlock do # ~FC017: LWRP does not notify when updated
|
74
|
+
user_resource :unlock
|
75
|
+
home_dir_resource :create
|
76
|
+
authorized_keys_resource :create
|
77
|
+
keygen_resource :create
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def bool(resource_val, default_val)
|
83
|
+
if resource_val.nil?
|
84
|
+
normalize_bool(default_val)
|
85
|
+
else
|
86
|
+
normalize_bool(resource_val)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def normalize_bool(val)
|
91
|
+
case val
|
92
|
+
when 'no','false',false then false
|
93
|
+
else true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def user_resource(exec_action)
|
98
|
+
# avoid variable scoping issues in resource block
|
99
|
+
my_home, my_shell, manage_home, non_unique = @my_home, @my_shell, @manage_home, @non_unique
|
100
|
+
my_dir = ::File.dirname(my_home)
|
101
|
+
|
102
|
+
r = directory "#{my_home} parent directory" do
|
103
|
+
path my_dir
|
104
|
+
recursive true
|
105
|
+
action :nothing
|
106
|
+
end
|
107
|
+
r.run_action(:create) unless exec_action == :delete
|
108
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
109
|
+
|
110
|
+
r = user new_resource.username do
|
111
|
+
comment new_resource.comment if new_resource.comment
|
112
|
+
uid new_resource.uid if new_resource.uid
|
113
|
+
gid new_resource.gid if new_resource.gid
|
114
|
+
home my_home if my_home
|
115
|
+
shell my_shell if my_shell
|
116
|
+
password new_resource.password if new_resource.password
|
117
|
+
system new_resource.system_user # ~FC048: Prefer Mixlib::ShellOut
|
118
|
+
supports :manage_home => manage_home, :non_unique => non_unique
|
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
|
+
|
124
|
+
# fixes CHEF-1699
|
125
|
+
Etc.endgrent
|
126
|
+
end
|
127
|
+
|
128
|
+
def home_dir_resource(exec_action)
|
129
|
+
# avoid variable scoping issues in resource block
|
130
|
+
my_home = @my_home
|
131
|
+
r = directory my_home do
|
132
|
+
path my_home
|
133
|
+
owner new_resource.username
|
134
|
+
group Etc.getpwnam(new_resource.username).gid
|
135
|
+
mode node['user']['home_dir_mode']
|
136
|
+
recursive true
|
137
|
+
action :nothing
|
138
|
+
end
|
139
|
+
r.run_action(exec_action)
|
140
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
141
|
+
end
|
142
|
+
|
143
|
+
def home_ssh_dir_resource(exec_action)
|
144
|
+
# avoid variable scoping issues in resource block
|
145
|
+
my_home = @my_home
|
146
|
+
r = directory "#{my_home}/.ssh" do
|
147
|
+
path "#{my_home}/.ssh"
|
148
|
+
owner new_resource.username
|
149
|
+
group Etc.getpwnam(new_resource.username).gid
|
150
|
+
mode '0700'
|
151
|
+
recursive true
|
152
|
+
action :nothing
|
153
|
+
end
|
154
|
+
r.run_action(exec_action)
|
155
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
def authorized_keys_resource(exec_action)
|
160
|
+
# avoid variable scoping issues in resource block
|
161
|
+
ssh_keys = Array(new_resource.ssh_keys)
|
162
|
+
unless ssh_keys.empty?
|
163
|
+
home_ssh_dir_resource(exec_action)
|
164
|
+
|
165
|
+
r = template "#{@my_home}/.ssh/authorized_keys" do
|
166
|
+
cookbook 'user'
|
167
|
+
source 'authorized_keys.erb'
|
168
|
+
owner new_resource.username
|
169
|
+
group Etc.getpwnam(new_resource.username).gid
|
170
|
+
mode '0600'
|
171
|
+
variables :user => new_resource.username,
|
172
|
+
:ssh_keys => ssh_keys,
|
173
|
+
:fqdn => node['fqdn']
|
174
|
+
action :nothing
|
175
|
+
end
|
176
|
+
|
177
|
+
r.run_action(exec_action)
|
178
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def keygen_resource(exec_action)
|
183
|
+
# avoid variable scoping issues in resource block
|
184
|
+
fqdn, my_home = node['fqdn'], @my_home
|
185
|
+
|
186
|
+
e = execute "create ssh keypair for #{new_resource.username}" do
|
187
|
+
cwd my_home
|
188
|
+
user new_resource.username
|
189
|
+
command <<-KEYGEN.gsub(/^ +/, '')
|
190
|
+
ssh-keygen -t rsa -f #{my_home}/.ssh/id_rsa -N '' \
|
191
|
+
-C '#{new_resource.username}@#{fqdn}-#{Time.now.strftime('%FT%T%z')}'
|
192
|
+
chmod 0600 #{my_home}/.ssh/id_rsa
|
193
|
+
chmod 0644 #{my_home}/.ssh/id_rsa.pub
|
194
|
+
KEYGEN
|
195
|
+
action :nothing
|
196
|
+
|
197
|
+
creates "#{my_home}/.ssh/id_rsa"
|
198
|
+
end
|
199
|
+
home_ssh_dir_resource(exec_action)
|
200
|
+
e.run_action(:run) if @ssh_keygen && exec_action == :create
|
201
|
+
new_resource.updated_by_last_action(true) if e.updated_by_last_action?
|
202
|
+
|
203
|
+
if exec_action == :delete then
|
204
|
+
["#{@my_home}/.ssh/id_rsa", "#{@my_home}/.ssh/id_rsa.pub"].each do |keyfile|
|
205
|
+
r = file keyfile do
|
206
|
+
backup false
|
207
|
+
action :delete
|
208
|
+
end
|
209
|
+
new_resource.updated_by_last_action(true) if r.updated_by_last_action?
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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
|
+
groups = {}
|
32
|
+
|
33
|
+
# only manage the subset of users defined
|
34
|
+
Array(user_array).each do |i|
|
35
|
+
u = data_bag_item(bag, i.gsub(/[.]/, '-'))
|
36
|
+
username = u['username'] || u['id']
|
37
|
+
|
38
|
+
user_account username do
|
39
|
+
%w{comment uid gid home shell password system_user manage_home create_group
|
40
|
+
ssh_keys ssh_keygen non_unique}.each do |attr|
|
41
|
+
send(attr, u[attr]) if u[attr]
|
42
|
+
end
|
43
|
+
action Array(u['action']).map { |a| a.to_sym } if u['action']
|
44
|
+
end
|
45
|
+
|
46
|
+
unless u['groups'].nil? || u['action'] == 'remove'
|
47
|
+
u['groups'].each do |groupname|
|
48
|
+
groups[groupname] = [] unless groups[groupname]
|
49
|
+
groups[groupname] += [username]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
groups.each do |groupname, users|
|
55
|
+
group groupname do
|
56
|
+
members users
|
57
|
+
append true
|
58
|
+
end
|
59
|
+
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,41 @@
|
|
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 :non_unique, :default => nil
|
34
|
+
attribute :create_group, :default => nil
|
35
|
+
attribute :ssh_keys, :kind_of => [Array,String], :default => []
|
36
|
+
attribute :ssh_keygen, :default => nil
|
37
|
+
|
38
|
+
def initialize(*args)
|
39
|
+
super
|
40
|
+
@action = :create
|
41
|
+
end
|