users Package¶
users Package¶
Roles in this namespace are meant to enable user management in CentOS distributions.
user Module¶
Roles in this namespace are meant to provide user management operations for CentOS distributions.
-
class
provy.more.centos.users.user.UserRole(prov, context)[source]¶ Bases:
provy.core.roles.RoleThis role provides many utility methods for user management operations within CentOS distributions.
Example:
from provy.core import Role from provy.more.centos import UserRole class MySampleRole(Role): def provision(self): with self.using(UserRole) as role: role.ensure_user('myuser', identified_by='mypass', is_admin=True)
-
ensure_group(group_name, group_id=None)[source]¶ Ensures that a given user group is present in the remote server.
Parameters: - group_name (
str) – Name of the group to create. - group_id (
int) – GID of the group. Defaults toNone, which assigns the next available GID.
Example:
from provy.core import Role from provy.more.centos import UserRole class MySampleRole(Role): def provision(self): with self.using(UserRole) as role: role.ensure_group('users-group')
- group_name (
-
ensure_user(username, identified_by=None, home_folder=None, default_script='/bin/bash', groups=[], is_admin=False)[source]¶ Ensures that a given user is present in the remote server.
Parameters: - username (
str) – Name of the user. - identified_by (
str) – Password that the user will use to login to the remote server. If set toNone, the user will not have a password. - user_id (
str) – UID of the user. Defaults toNone, which assigns the next available UID. - home_folder (
str) – Specifies the user’s home folder. Defaults to /home/<username>. - default_script (
str) – Sets the user’s default script, the one that will execute commands per default when logging in. Defaults to /bin/sh. - groups (
iterable) – Groups that this user belongs to. If the groups do not exist they are created prior to user creation. Defaults to the name of the user. - is_admin (
bool) – If set toTruethe user is added to the ‘wheel’ user group as well. Defaults toFalse.
Example:
from provy.core import Role from provy.more.centos import UserRole class MySampleRole(Role): def provision(self): with self.using(UserRole) as role: role.ensure_user('myuser', identified_by='mypass', is_admin=True)
- username (
-
group_exists(group_name)[source]¶ Returns
Trueif the given group exist,Falseotherwise.Parameters: group_name ( str) – Name of the group to verify.Returns: Whether the group exists or not. Return type: boolExample:
class MySampleRole(Role): def provision(self): with self.using(UserRole) as role: if role.group_exists('usersgroup'): pass
-
user_exists(username)[source]¶ Returns
Trueif the given user exist,Falseotherwise.Parameters: username ( str) – Name of the user to verify.Returns: Whether the user exists or not. Return type: boolExample:
class MySampleRole(Role): def provision(self): with self.using(UserRole) as role: if role.user_exists('myuser'): pass
-
user_in_group(username, group_name)[source]¶ Returns
Trueif the given user is in the given group,Falseotherwise.Parameters: - username (
str) – Name of the user to verify. - group_name (
str) – Name of the group to verify.
Returns: Whether the user pertains to the group or not.
Return type: boolExample:
from provy.core import Role from provy.more.centos import UserRole class MySampleRole(Role): def provision(self): with self.using(UserRole) as role: if role.user_in_group('myuser', 'mygroup'): pass
- username (
-