Ansible role for managing users and groups on Linux hosts.
-
install requirements
pip3 install -r requirements.txt
-
community.posix ansible collection
-
install
ansible collectionrequirementsansible-galaxy install -r requirements.yml
Create and manage user groups on target hosts.
When a group is removed from this variable, the associated group on the hosts will be deleted.
Each entry in the users_groups list can contain the following keys:
name: The name of the group to create or manage. Required.gid: The group ID number. If not specified, the system assigns the next available GID.system: Specifies whether the group is a system group. Default:false.local: Forces the use of "local" command alternatives on platforms that implement it. Default:falsestate: state of group, "present" group creation, "absent" group deletion. . Default:present
Create and manage users on target hosts.
When a user is removed from this variable, the associated user on the hosts will be deleted.
Each entry in the users_users list can contain the following keys:
Note:
When adding a user to an additional group or granting
sudoprivileges, ensure that theappendoption is set totrue(which is the default). If you do not want to append the user to additional group or assignsudorights, set append tofalse.
Using append:falsewill remove the user from all other groups, which might lead to loss of necessary permissions or access. Ensure this is the intended behavior before applying.
name: The username of the account to create or manage. Required.password: The encrypted user password.update_password: Specifies when to update the password. Can bealwaysoron_create.shell: The user's login shell. Default:/bin/bash.uid: The user ID number. If not specified, the system assigns the next available UID.comment: The GECOS field.home: Path to the user's home directory.create_home: Create the home directory if it doesn't exist.expires: Account expiration date in epoch. Can be removed by specifying a-1.group: User's primary group name.groups: List of additional groups the user belongs to.sudoer: Make user sudoer. Default:false.append: Whether to append to the groups list or replace it. Default:false.non_unique: Allow duplicate UIDs. Default:false.system: Create a system account. Default:false.local: Forces the use of "local" command alternatives on platforms that implement it. Default:false.state: state of user, "present" user creation, "absent" user deletion. . Default:presentssh_key: SSH public key to add to authorized_keys. Can be multiline.ssh_key_options: SSH options for the key.ssh_comment: A comment for the SSH key.ssh_exclusive: Remove all other keys from the authorized_keys file.
Defines whether the home directory will be deleted when the user is deleted. Default: false.
Forced deletion of a user, associated directories and groups. Default: false.
Forced deletion of a group. Default: false.
Licensed under the MIT License. See the LICENSE file for details.
Ali Mehraji
[email protected]