oasis_roles.users_and_groups
This Role Has Been Deprecated: Please use the version in the oasis_roles.system Ansible Collection
users_and_groups
Ansible role that manages groups and users
Requirements
Ansible 2.8 or higher
Red Hat Enterprise Linux 7 or equivalent
Valid Red Hat Subscriptions
Role Variables
Currently the following variables are supported:
General
Sub-field format guide: parameter - [input type] (application scenario) Description. Importance|Default value
OPTIONAL tags means there is no default value.
users_and_groups_add_modify_groups- A list of groups to create/modify on remote hosts. Each list entry has the following parameters (in depth descriptions of some parameters can be found in the group module docs):name- [string] (add|modify) The name of the group. REQUIREDgid- [int] (add|modify) GID to set for the group. OPTIONALlocal- [bool] (add) Forces the use of "local" command alternatives on platforms that implement it. Default isfalsenon_unique- [bool] (add|modify) Allows admin to change the GID to a non-unique value. Requires gid to be defined. Default isfalsesystem- [bool] (add) Indicates the group is a system group if set totrue. Default isfalse
users_and_groups_remove_groups- A list of groups to remove/delete from remote hostsusers_and_groups_add_modify_users- A list of users to create/modify on remote hosts. Each list entry has the following parameters (in depth descriptions of some parameters can be found in the user module docs):name- [string] (add|modify) The name of the user to manage. REQUIREDauthorization- [string list] (add|modify) Sets the authorization of the user. OPTIONALcomment- [string] (add|modify) Sets the description of the user account. OPTIONALcreate_home- [bool] (add) Unless set tofalse, a home directory will be made for the user upon creation. Default istrueexpires- [float] (add|modify) An expiry time for the user in epoch. Specify a negative value to remove an existing expiry time. OPTIONALforce- [bool] (add|modify) Used withgenerate_ssh_keyto force the overwrite of an existing ssh key. Default isfalsegenerate_ssh_key- [bool] (add|modify) Whether or not to generate a ssh key for the specified user. Will not overwrite an existing key unlessforce: trueis specified. Default isfalsehome- [path] (add) Set the user's home directory OPTIONALlocal- [bool] (add) Forces the use of "local" command alternatives on platforms that implement it. Default isfalselogin_class- [string] (add) Set the user's login class. OPTIONALmove_home- [bool] (modify) Whentrueandhome:is defined, attempts to move the user's old home to the new path specified inhome:. Default isfalsenon_unique- [bool] (modify) Allows the user's UID to change to a non-unique value. Default isfalsepassword- [string] (add|modify) Set the user's password to this crypted value. See the ansible docs for generating password values. OPTIONALpassword_lock- [bool] (add|modify) Lock the user's password. OPTIONALprofile- [string list] (add|modify) Sets the profile of the user. OPTIONALrole- [string list] (add|modify) Sets the role of the user. OPTIONALseuser- [string] (add|modify) Sets the seuser type on selinux enabled systems. OPTIONALshell- [string] (add|modify) Sets the user's shell. OPTIONALskeleton- [string] (add) Set a home skeleton directory. Requirescreate_hometo be defined. OPTIONALssh_key_bits- [int] (add|modify) Specify number of bits in SSH key to create. OPTIONALssh_key_comment- [string] (add|modify) Description for a SSH key. OPTIONALssh_key_file- [path] (add|modify) Specify the SSH key filename. Relative filenames are relative to the user's home directory. Default is.ssh/id_rsassh_key_passphrase- [string] (add|modify) Set a passphrase for a SSH key. OPTIONALssh_key_type- [string] (add|modify) The type of SSH key to generate. Default is"rsa"system- [bool] (add) Whentrue, the user becomes a system account. Default isfalseuid- [int] (add|modify) Sets the UID of the user. OPTIONALupdate_password- [string] (add|modify) When"always", user's password will be updated ifpassworddiffers from the current password. When"on_create", user's password will be set topasswordfor newly created users only. Default is"always"
users_and_groups_remove_users- A list of users to remove/delete from remote hosts. Each list entry has the following parameters (in depth descriptions of some parameters can be found in the user module docs)name- [string] The name of the user to be removed. REQUIREDforce- [bool] Forces the removal of the user and associated directories whentrue. Default isfalseremove- [bool] Attempts to remove directories associated with the user whentrue. Default isfalse
users_and_groups_add_group_members- A list of users to grant/modify membership to specified groups. Each list entry has the following parameters (in depth descriptions of some parameters can be found in the user module docs)name- [string] (add|modify) Name of the user whose group membership is being modified. REQUIREDappend- [bool] (add|modify) Whentrue, adds specified groups to current membership. Whenfalse, replaces current membership with specified groups. Default isfalseprimary_group- [string] (add|modify) Assign a primary group for the specified user. OPTIONAL (listed asgroupin module docs)groups- [string list] (add|modify) List of groups user will become a member of. REQUIRED
users_and_groups_remove_group_members- A list of users to revoke membership to specified groups. Each list entry has the following parameters (in depth descriptions of some parameters can be found in the user module docs)name- [string] Name of the user whose group membership is being modified. REQUIREDprimary_group- [string] Reassign a primary group for the specified user. OPTIONAL (listed asgroupin module docs)groups- [string list] List of groups user will be removed from. REQUIRED
users_and_groups_become- Default: true. If this role needs administrator privileges, then use the Ansible become functionality (based off sudo).users_and_groups_become_user- Default: root. If the role uses the become functionality for privilege escalation, then this is the name of the target user to change to.
Dependencies
None
Example Playbook
This example adds/modifies groups to remote hosts while removing/deleting others
- hosts: users_and_groups-servers
roles:
- role: oasis_roles.users_and_groups
vars:
users_and_groups_add_modify_groups:
- name: "test_group1"
gid: 30
system: true
- name: "test_group2"
gid: 31
local: true
- name: "test_group3"
users_and_groups_remove_groups:
- "test_group4"
- "test_group5"
This example adds/modifies users to the remote host while removing/deleting others
- hosts: users_and_groups-servers
roles:
- role: oasis_roles.users_and_groups
vars:
users_and_groups_add_modify_users:
- name: "john_doe"
comment: "This is John Doe's user description"
password: "EnCrYpTeD Pa$$W0Rd"
uid: 1200
- name: "laura_smith"
role:
- administrator
- tester
- developer
ssh_key_bits: 256
ssh_key_file: /path/to/ssh/key/file
ssh_key_passphrase: "my_SSH^passPhrasE"
system: true
users_and_groups_remove_users:
- name: "brad_cooper"
remove: true
force: true
- name: "thomas"
This example adds new members to groups while removing members from other groups. When removing "alex" from "old_group2", the user's primary_group is reassigned as the user's previous primary_group was old_group2
- hosts: users_and_groups-servers
roles:
- role: oasis_roles.users_and_groups
vars:
users_and_groups_add_group_members:
- name: "john_doe"
groups:
- "group1"
- "group2"
primary_group: "group1"
append: false
- name: "jane_smith"
groups:
- "new_group2"
append: true
users_and_groups_remove_group_members:
- name: "jane_smith"
groups:
- "old_group1"
- "old_group2"
- name: "alex"
groups:
- "old_group2"
primary_group: "group2"
License
GPLv3
Author Information
Andrew Euredjian aeuredji@redhat.com
ansible-galaxy install oasis_roles.users_and_groups