From f1eb517563101b5f86e0797cb2a427aac50363d4 Mon Sep 17 00:00:00 2001 From: L3D Date: Thu, 8 Aug 2024 16:39:28 +0200 Subject: [PATCH] Create variable for additional groups Addoption to create groups CLOSE https://github.com/roles-ansible/ansible_collection_users/issues/26 --- README.md | 1 + roles/user/README.md | 1 + roles/user/defaults/main.yml | 1 + roles/user/tasks/users.yml | 7 +++++++ roles/user/vars/main.yml | 2 +- 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 40daaca..50c8ed5 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ There is also the ``l3d_users__ssh_login`` variable which only supports ``name`` | ``l3d_users__ansible_user_command`` | ``ALL`` | Commans with superpower for ansible user | | ``l3d_users__ansible_user_nopassword`` | ``true`` | Allow superpowers without password for ansible user | | ``l3d_users__limit_login`` | ``true`` | Only allow SSH login for specified users | +| ``l3d_users__additional_groups`` | ``[]`` | Optionally create some groups | | ``l3d_users__sshd_port`` | ``22`` | Port for SSH | | ``l3d_users__sshd_password_authentication`` | ``false`` | Allow login with Password | | ``l3d_users__sshd_permitrootlogin`` | ``false`` | Allow login as root | diff --git a/roles/user/README.md b/roles/user/README.md index a1b1650..afd52b9 100644 --- a/roles/user/README.md +++ b/roles/user/README.md @@ -46,6 +46,7 @@ The Option of these directory-variables are the following. | ``l3d_users__set_root_ssh_keys`` | ``false`` | Set SSH Keys for root User | | ``l3d_users__root_ssh_keys`` | | Additional SSH Keys for root User | | ``submodules_versioncheck`` | ``false`` | Optionaly enable simple versionscheck of this role | +| ``l3d_users__additional_groups`` | ``[]`` | Optionally create some groups | Example Playbook ----------------- diff --git a/roles/user/defaults/main.yml b/roles/user/defaults/main.yml index 8044d98..abca880 100644 --- a/roles/user/defaults/main.yml +++ b/roles/user/defaults/main.yml @@ -37,6 +37,7 @@ l3d_users__ansible_ssh_keys: "{{ lookup('url', 'https://github.com/do1jlr.keys', l3d_users__ansible_user_password: '' l3d_users__set_root_ssh_keys: false l3d_users__root_ssh_keys: '' +l3d_users__additional_groups: [] # run simple versionscheck submodules_versioncheck: false diff --git a/roles/user/tasks/users.yml b/roles/user/tasks/users.yml index 72cac61..81e1f26 100644 --- a/roles/user/tasks/users.yml +++ b/roles/user/tasks/users.yml @@ -10,6 +10,13 @@ loop_var: user when: user.state | default ('present') == 'present' +- name: Optionally create additional Groups + become: true + ansible.builtin.group: + name: "{{ item }}" + state: 'present' + with_items: "{{ l3d_users__additional_groups }}" + - name: Create Accounts for Users become: true ansible.builtin.user: diff --git a/roles/user/vars/main.yml b/roles/user/vars/main.yml index 9ff55a7..f44d906 100644 --- a/roles/user/vars/main.yml +++ b/roles/user/vars/main.yml @@ -1,3 +1,3 @@ --- -playbook_version_number: 16 +playbook_version_number: 17 playbook_version_path: 'l3d.users.user.version'