Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/radiorabe/actions-…
Browse files Browse the repository at this point in the history
…0.22.0
  • Loading branch information
smirta authored Jul 2, 2024
2 parents 073efa8 + aa581a8 commit c2af8b7
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Contains common roles and playbooks.
* [`core`](https://github.com/radiorabe/ansible-collection-common/tree/main/roles/core)
* [`download_file`](https://github.com/radiorabe/ansible-collection-common/tree/main/roles/download_file) (download single file)
* [`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)
* [`local_user`](https://github.com/radiorabe/ansible-collection-common/tree/main/roles/local_user) (for local user creation)

## License

Expand Down
38 changes: 0 additions & 38 deletions roles/local_system_user/README.md

This file was deleted.

4 changes: 0 additions & 4 deletions roles/local_system_user/defaults/main.yml

This file was deleted.

11 changes: 0 additions & 11 deletions roles/local_system_user/tasks/main.yml

This file was deleted.

46 changes: 46 additions & 0 deletions roles/local_user/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Ansible Role - radiorabe.common.local_user

Manage local users.

## Requirements

None

## Role Variables

| Variable | Default | Description |
| -------- | ------- | ----------- |
| `local_user_additional_usergroups` | `''` | Existing groups the user should be added to. |
| `local_user_create_home` | `false` | Create user home directory. |
| `local_user_groupname` | `''` | Name of the primary group the user belongs to. |
| `local_user_home_directory` | `''` | Home directory of the user. |
| `local_user_username` | `not set` | Name of the user. **required** |
| `local_user_shell` | `''` | Set shell for user. |
| `local_user_system` | `false` | Set this to true if it should be a system user (uid < 1000). |

## Dependencies

None

## Example Playbook

```yaml
- hosts: all
roles:
- role: radiorabe.common.local_user
vars:
local_user_username: test
- role: radiorabe.common.local_user
vars:
local_user_additional_groups: 'libvirt,qemu'
local_user_create_home: true
local_user_groupname: local-systemuser
local_user_home_directory: /home/localsys
local_user_shell: '/usr/sbin/nologin'
local_user_system: true
local_user_username: local-sysuser
```
## 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.
8 changes: 8 additions & 0 deletions roles/local_user/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# defaults for radiorabe.common.local_user

local_user_additional_groups: ''
local_user_create_home: false
local_user_groupname: ''
local_user_home_directory: ''
local_user_shell: ''
local_user_system: false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
galaxy_info:
author: RaBe IT-Reaktion
description: Allow managing of local system users.
description: Allow managing of local users.
issue_tracker_url: https://github.com/radiorabe/ansible-collection-common/issues
license: AGPL-3.0-only
min_ansible_version: '2.9'
Expand Down
51 changes: 51 additions & 0 deletions roles/local_user/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# tasks file for radiorabe.common.local_user

- name: 'Get {{ local_user_username }} user info'
ansible.builtin.getent:
database: passwd
key: '{{ local_user_username }}'
ignore_errors: true

- name: 'Get {{ local_user_groupname }} group'
ansible.builtin.getent:
database: group
key: '{{ local_user_groupname }}'
ignore_errors: true

- name: 'Add group when does not exist'
become: true
command: groupadd {{ local_user_groupname }}
when:
ansible_facts.getent_group is undefined and
local_user_groupname != ''

- name: 'Add user and group when does not exist'
become: true
ansible.builtin.command:
argv: "{{ cmd_argv |
zip(cmd_argv_switch) |
selectattr('1') |
map(attribute='0') | list }}"
vars:
cmd_argv:
- 'useradd'
- '--create-home'
- '--groups="{{ local_user_additional_groups }}"'
- '--gid="{{ local_user_groupname }}"'
- '--home-dir="{{ local_user_home_directory }}"'
- '--shell="{{ local_user_shell }}"'
- '--system'
- '--add-subids-for-system'
- '{{ local_user_username }}'
cmd_argv_switch:
- true
- '{{ local_user_create_home }}'
- '{{ local_user_additional_groups != "" }}'
- '{{ local_user_groupname != "" }}'
- '{{ local_user_home_directory != "" }}'
- '{{ local_user_shell != "" }}'
- '{{ local_user_system }}'
- '{{ local_user_system }}'
- true
when: ansible_facts.getent_passwd is undefined

0 comments on commit c2af8b7

Please sign in to comment.