-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/github_actions/radiorabe/actions-…
…0.22.0
- Loading branch information
Showing
8 changed files
with
107 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 1 addition & 1 deletion
2
roles/local_system_user/meta/main.yml → roles/local_user/meta/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |