Class: AutomateIt::AccountManager
- Inherits:
-
Plugin::Manager
- Object
- Common
- Plugin::Base
- Plugin::Manager
- AutomateIt::AccountManager
- Defined in:
- lib/automateit/account_manager.rb
Overview
AccountManager
The AccountManager provides a way of managing system accounts, such as Unix users and groups.
Defined Under Namespace
Classes: BaseDriver, Linux, Portable
Constant Summary
Constants included from Constants
Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE
Instance Attribute Summary
Attributes inherited from Plugin::Manager
Attributes inherited from Common
Instance Method Summary collapse
-
#add_group(groupname, opts = {}) ⇒ Object
Add
groupname
if it doesn’t exist. -
#add_groups_to_user(groups, user) ⇒ Object
Add
groups
(array of groupnames) touser
. -
#add_user(username, opts = {}) ⇒ Object
Add the
username
if not already created. -
#add_users_to_group(users, group) ⇒ Object
Add
users
(array of usernames) togroup
. -
#groups ⇒ Object
Find a group.
-
#groups_for_user(query) ⇒ Object
Array of groupnames this user is a member of.
-
#has_group?(group) ⇒ Boolean
Does
group
exist?. -
#has_user?(user) ⇒ Boolean
Is
user
present?. -
#passwd(user, password) ⇒ Object
Change the
password
for theuser
. -
#remove_group(groupname, opts = {}) ⇒ Object
Remove
groupname
if it exists. -
#remove_groups_from_user(groups, user) ⇒ Object
Remove
groups
(array of groupnames) fromuser
. -
#remove_user(username, opts = {}) ⇒ Object
Remove the
username
if present. -
#remove_users_from_group(users, group) ⇒ Object
Remove
users
(array of usernames) fromgroup
. -
#users ⇒ Object
Find a user account.
-
#users_for_group(query) ⇒ Object
Array of usernames in group.
-
#users_to_groups ⇒ Object
Hash of usernames and the groupnames they’re members of.
Methods inherited from Plugin::Manager
#[], abstract_manager, alias_methods, #available?, #default, #default=, #dispatch, #dispatch_safely, #dispatch_safely_to, #dispatch_to, driver_classes, #driver_for, #driver_suitability_levels_for, inherited, #instantiate_drivers, #setup
Methods inherited from Plugin::Base
Methods inherited from Common
#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?
Constructor Details
This class inherits a constructor from AutomateIt::Common
Instance Method Details
#add_group(groupname, opts = {}) ⇒ Object
Add groupname
if it doesn’t exist. Options:
-
:members – Array of usernames to add as members.
-
:gid – Group ID to use. Default is to find an unused id.
70 |
# File 'lib/automateit/account_manager.rb', line 70 def add_group(groupname, opts={}) dispatch(groupname, opts) end |
#add_groups_to_user(groups, user) ⇒ Object
Add groups
(array of groupnames) to user
.
47 |
# File 'lib/automateit/account_manager.rb', line 47 def add_groups_to_user(groups, user) dispatch(groups, user) end |
#add_user(username, opts = {}) ⇒ Object
Add the username
if not already created.
Options:
-
:description – User’s full name. Defaults to username.
-
:home – Path to user’s home directory. If not specified, uses system default like “/home/username”.
-
:create_home – Create homedir. Defaults to true.
-
:groups – Array of group names to add this user to.
-
:shell – Path to login shell. If not specified, uses system default like “/bin/bash”.
-
:uid – Fixnum user ID for user. Default chooses an unused id.
-
:gid – Fixnum group ID for user. Default chooses same gid as uid.
Example:
add_user("bob", :description => "Bob Smith")
31 |
# File 'lib/automateit/account_manager.rb', line 31 def add_user(username, opts={}) dispatch(username, opts) end |
#add_users_to_group(users, group) ⇒ Object
Add users
(array of usernames) to group
.
82 |
# File 'lib/automateit/account_manager.rb', line 82 def add_users_to_group(users, group) dispatch(users, group) end |
#groups ⇒ Object
Find a group. Method returns a query helper which takes a groupname
as an index argument and returns a Struct::Group entry as described in Etc::getgrent if the group exists or a nil if not.
Example:
groups["root"] # => #<struct Struct::Group name="root"...
groups["does_not_exist"] # => nil
65 |
# File 'lib/automateit/account_manager.rb', line 65 def groups() dispatch() end |
#groups_for_user(query) ⇒ Object
Array of groupnames this user is a member of.
88 |
# File 'lib/automateit/account_manager.rb', line 88 def groups_for_user(query) dispatch(query) end |
#has_group?(group) ⇒ Boolean
Does group
exist?
79 |
# File 'lib/automateit/account_manager.rb', line 79 def has_group?(group) dispatch(group) end |
#has_user?(user) ⇒ Boolean
Is user
present?
44 |
# File 'lib/automateit/account_manager.rb', line 44 def has_user?(user) dispatch(user) end |
#passwd(user, password) ⇒ Object
Change the password
for the user
.
53 |
# File 'lib/automateit/account_manager.rb', line 53 def passwd(user, password) dispatch(user, password) end |
#remove_group(groupname, opts = {}) ⇒ Object
Remove groupname
if it exists.
76 |
# File 'lib/automateit/account_manager.rb', line 76 def remove_group(groupname, opts={}) dispatch(groupname, opts) end |
#remove_groups_from_user(groups, user) ⇒ Object
Remove groups
(array of groupnames) from user
.
50 |
# File 'lib/automateit/account_manager.rb', line 50 def remove_groups_from_user(groups, user) dispatch(groups, user) end |
#remove_user(username, opts = {}) ⇒ Object
Remove the username
if present.
Options:
-
:remove_home – Delete user’s home directory and mail spool. Default is true.
41 |
# File 'lib/automateit/account_manager.rb', line 41 def remove_user(username, opts={}) dispatch(username, opts) end |
#remove_users_from_group(users, group) ⇒ Object
Remove users
(array of usernames) from group
.
85 |
# File 'lib/automateit/account_manager.rb', line 85 def remove_users_from_group(users, group) dispatch(users, group) end |
#users ⇒ Object
Find a user account. Method returns a query helper which takes a username
as an index argument and returns a Struct::Passwd entry as described in Etc::getpwent if the user exists or a nil if not.
Example:
users["root"] # => #<struct Struct::Passwd name="root"...
users["does_not_exist"] # => nil
14 |
# File 'lib/automateit/account_manager.rb', line 14 def users() dispatch() end |
#users_for_group(query) ⇒ Object
Array of usernames in group.
91 |
# File 'lib/automateit/account_manager.rb', line 91 def users_for_group(query) dispatch(query) end |
#users_to_groups ⇒ Object
Hash of usernames and the groupnames they’re members of.
94 |
# File 'lib/automateit/account_manager.rb', line 94 def users_to_groups() dispatch() end |