Skip to content

Commit

Permalink
feat(local-system-user): add local system user role (#45)
Browse files Browse the repository at this point in the history
* feat(local-system-uer): add local system user role

* feat(local-system-user): Readme update and shell /sbin/nologin added
  • Loading branch information
smirta authored Jun 4, 2024
1 parent 6f7a452 commit c0d1f6f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Contains common roles and playbooks.
* [`core`](https://github.com/radiorabe/ansible-collection-common/tree/main/roles/core)
* [`base`](https://github.com/radiorabe/ansible-collection-common/tree/main/roles/base)
* [`files`](https://github.com/radiorabe/ansible-collection-common/tree/main/roles/files) (for quick and dirty file management)
* [`local-system-user`](https://github.com/radiorabe/ansible-collection-common/tree/main/roles/local-system-user) (for local system user creation)

## License

Expand Down
40 changes: 40 additions & 0 deletions roles/local-system-user/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Ansible Role - radiorabe.common.local-system-user

Manage local system users using [`ansible.builtin.user module`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/user_module.html). Shell or password won't be set with this role.

## Requirements

None

## Role Variables

| Variable | Default | Description |
| -------- | ------- | ----------- |
| `username` | `not set` | Name of the user. **required** |
| `home_directory` | `/home/{{username}}` | Home directory of the user. |
| `usergroups` | `''` | Existing groups the user should be added to. |

## Dependencies

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

## Example Playbook

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

```yaml
- hosts: all
roles:
- role: radiorabe.common.local-system-user
vars:
username: local-sys
- role: radiorabe.common.local-system-user
vars:
username: virtualizer
home_directory: /var/lib/libvvirt/images/
usergroups: 'libvirt,qemu'
```
## License
This role is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
4 changes: 4 additions & 0 deletions roles/local-system-user/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# defaults for radiorabe.common.local-system-user

home_directory: '/home/{{username}}'
usergroups: ''
21 changes: 21 additions & 0 deletions roles/local-system-user/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
galaxy_info:
author: RaBe IT-Reaktion
description: Allow managing of local system users.
issue_tracker_url: https://github.com/radiorabe/ansible-collection-common/issues
license: AGPL-3.0-only
min_ansible_version: '2.9'
platforms:
- name: EL
versions:
- all
- name: Fedora
version:
- all
galaxy_tags:
- radiorabe
- foreman
- common
- system
- groups
- users
dependencies: []
11 changes: 11 additions & 0 deletions roles/local-system-user/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# tasks file for radiorabe.common.local-system-user

- name: 'RaBe Base : Local System User : Add user {{ username }} with groups {{ usergroups }} and user home {{ home_directory }}.'
ansible.builtin.user:
name: '{{ username }}'
home: '{{ home_directory }}'
groups: '{{ usergroups }}'
shell: '/sbin/nologin'
system: true
append: yes

0 comments on commit c0d1f6f

Please sign in to comment.