Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

DESCRIPTION:

Create and manage users and groups

DATABAGS:

users

{

"id"       : "username",
"name"     : "Real Name",
"uid"      : 10001,
"shell"    : "/bin/bash",
"password" : "$1$OWxipM7o$9aC2eh/NX0umkmX7Nf2mr1"

}

The “shell” and “password” fields are optional. Shell defaults to /bin/bash, and password defaults to “foo”.

To generate the password, do this:

$ openssl passwd -1

You will be prompted to enter your password (twice!) then a hash will pop out.

groups

{

"id"      : "group name",
"gid"     : 20001,
"members" : [
  "username",
  "otheruser"
]

}

All fields are required.

USAGE:

include_recipe "accounts"

… or, individually:

include_recipe "accounts::groups"
include_recipe "accounts::users"

LICENSE

Copyright 2010, Estately, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

#
# Cookbook Name:: accounts
# Recipe:: default
#
# Copyright 2010, Estately, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include_recipe "accounts::users"
include_recipe "accounts::groups"
#
# Cookbook Name:: accounts
# Recipe:: groups
#
# Copyright 2010, Estately, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
search( :groups ).each do |group|
group group[:id] do
gid group[ :gid ]
members group[ :members ]
action [ :create, :manage ]
end
end
{
"conflicting": {
},
"description": "Configures accounts",
"providing": {
},
"attributes": {
},
"platforms": {
},
"replacing": {
},
"dependencies": {
},
"recipes": {
},
"version": "0.1.0",
"groupings": {
},
"long_description": "= DESCRIPTION:\n\nCreate and manage users and groups\n\n= DATABAGS:\n\n== users\n\n{\n \"id\" : \"username\",\n \"name\" : \"Real Name\",\n \"uid\" : 10001,\n \"shell\" : \"/bin/bash\",\n \"password\" : \"$1$OWxipM7o$9aC2eh/NX0umkmX7Nf2mr1\"\n}\n\nThe \"shell\" and \"password\" fields are optional. Shell defaults to\n/bin/bash, and password defaults to \"foo\".\n\nTo generate the password, do this:\n\n $ openssl passwd -1\n\nYou will be prompted to enter your password (twice!) then a hash will\npop out.\n\n== groups\n\n{\n \"id\" : \"group name\",\n \"gid\" : 20001,\n \"members\" : [\n \"username\",\n \"otheruser\"\n ]\n}\n\nAll fields are required.\n\n= USAGE:\n\n include_recipe \"accounts\"\n\n... or, individually:\n\n include_recipe \"accounts::groups\"\n include_recipe \"accounts::users\"\n\n= LICENSE\n\nCopyright 2010, Estately, Inc.\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",
"recommendations": {
},
"license": "Apache 2.0",
"maintainer": "Ben Bleything",
"name": "accounts",
"suggestions": {
},
"maintainer_email": "ben@estately.com"
}
maintainer "Ben Bleything"
maintainer_email "ben@estately.com"
license "Apache 2.0"
description "Configures accounts"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
version "0.1"
#
# Cookbook Name:: accounts
# Recipe:: users
#
# Copyright 2010, Estately, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# libshadow is required to set passwords
package "libshadow-ruby1.8"
# remove the bootstrap user
user("bootstrap") { action :remove }
# create users from the users databag
search( "users" ).sort_by {|u| u[:uid] }.each do |user|
homedir = user[ :home ] || "/home/#{user[:id]}"
user user[:id] do
comment user[ :name ]
uid user[ :uid ]
shell user[ :shell ] || "/bin/bash"
password user[ :password ] || "$1$oBTQd/WJ$UBd0XfleEOk3.ZGZF9Ue30"
home homedir
supports :manage_home => true
action [ :create, :manage ]
end
directory homedir + "/.ssh" do
owner user[:id]
group user[:id]
mode 0700
end
file homedir + "/.ssh/authorized_keys" do
owner user[:id]
group user[:id]
mode 0644
content user[:ssh_keys].join("\n") + "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.