class AutomateIt::AccountManager

AccountManager

The AccountManager provides a way of managing system accounts, such as Unix users and groups.

Public Instance Methods

add_group(groupname, opts={}) click to toggle source

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.

# File lib/automateit/account_manager.rb, line 81
def add_group(groupname, opts={}) dispatch(groupname, opts) end
add_groups_to_user(groups, user) click to toggle source

Add groups (array of groupnames) to user.

# File lib/automateit/account_manager.rb, line 58
def add_groups_to_user(groups, user) dispatch(groups, user) end
add_user(username, opts={}) click to toggle source

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")
# File lib/automateit/account_manager.rb, line 42
def add_user(username, opts={}) dispatch(username, opts) end
add_users_to_group(users, group) click to toggle source

Add users (array of usernames) to group.

# File lib/automateit/account_manager.rb, line 93
def add_users_to_group(users, group) dispatch(users, group) end
groups() click to toggle source

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
# File lib/automateit/account_manager.rb, line 76
def groups() dispatch() end
groups_for_user(query) click to toggle source

Array of groupnames this user is a member of.

# File lib/automateit/account_manager.rb, line 99
def groups_for_user(query) dispatch(query) end
has_group?(group) click to toggle source

Does group exist?

# File lib/automateit/account_manager.rb, line 90
def has_group?(group) dispatch(group) end
has_user?(user) click to toggle source

Is user present?

# File lib/automateit/account_manager.rb, line 55
def has_user?(user) dispatch(user) end
invalidate(database) click to toggle source

Invalidate system cache for database. The database can be either :users or :groups. This is necessary on operating systems that lack logic to notify their caching system that an entry changed. If the OS doesn’t need invalidation, will do nothing and return false.

This method is primarily for the sake of driver authors, recipe authors will probably never need to use this.

# File lib/automateit/account_manager.rb, line 13
def invalidate(database) dispatch_safely(database) end
passwd(user, password, opts={}) click to toggle source

Change the password for the user.

# File lib/automateit/account_manager.rb, line 64
def passwd(user, password, opts={}) dispatch(user, password, opts) end
remove_group(groupname, opts={}) click to toggle source

Remove groupname if it exists.

# File lib/automateit/account_manager.rb, line 87
def remove_group(groupname, opts={}) dispatch(groupname, opts) end
remove_groups_from_user(groups, user) click to toggle source

Remove groups (array of groupnames) from user.

# File lib/automateit/account_manager.rb, line 61
def remove_groups_from_user(groups, user) dispatch(groups, user) end
remove_user(username, opts={}) click to toggle source

Remove the username if present.

Options:

  • :remove_home – Delete user’s home directory and mail spool. Default is true.

# File lib/automateit/account_manager.rb, line 52
def remove_user(username, opts={}) dispatch(username, opts) end
remove_users_from_group(users, group) click to toggle source

Remove users (array of usernames) from group.

# File lib/automateit/account_manager.rb, line 96
def remove_users_from_group(users, group) dispatch(users, group) end
users() click to toggle source

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
# File lib/automateit/account_manager.rb, line 25
def users() dispatch() end
users_for_group(query) click to toggle source

Array of usernames in group.

# File lib/automateit/account_manager.rb, line 102
def users_for_group(query) dispatch(query) end
users_to_groups() click to toggle source

Hash of usernames and the groupnames they’re members of.

# File lib/automateit/account_manager.rb, line 105
def users_to_groups() dispatch() end