From e9e609e89ad879e10e58f2c4fcfa572f60d6dfad Mon Sep 17 00:00:00 2001 From: Ahmed Abdelhalim Date: Wed, 10 Sep 2025 17:52:58 +0200 Subject: Refactor role dependencies to be more module modular This modularity means that each role can be installed in a playbook by itself as long as the other roles exist around it. This also straps the ensure dependency packages exist in any of the roles tasks, they should be moved to their own roles and configured properly if needed. --- roles/user/meta/main.yml | 3 ++- roles/user/tasks/main.yml | 24 +----------------------- 2 files changed, 3 insertions(+), 24 deletions(-) (limited to 'roles/user') diff --git a/roles/user/meta/main.yml b/roles/user/meta/main.yml index 996a5fc3..50cb8081 100644 --- a/roles/user/meta/main.yml +++ b/roles/user/meta/main.yml @@ -1,6 +1,7 @@ --- dependencies: - - "bash" + - role: "bash" + - role: "sudo" galaxy_info: author: "a14m" description: "Configure user and sudo" diff --git a/roles/user/tasks/main.yml b/roles/user/tasks/main.yml index e6e2a306..8fcb101b 100644 --- a/roles/user/tasks/main.yml +++ b/roles/user/tasks/main.yml @@ -1,29 +1,7 @@ --- -- name: "Ensure sudo is installed" - become: true - ansible.builtin.package: - name: - - "sudo" - state: "present" - -- name: "Set sudo group fact" - ansible.builtin.set_fact: - # noqa var-naming[no-role-prefix] the sudo group is global and better named this way than user_sudo_group - sudo_group: "sudo" - - name: "Set user groups fact" ansible.builtin.set_fact: - user_groups: "{{ ([username, sudo_group] + user_groups) | unique }}" - -- name: "Configure permissions for group: {{ sudo_group }}" - become: true - community.general.sudoers: - name: "enable-sudo-group" - group: "{{ sudo_group }}" - commands: "ALL" - nopassword: false - sudoers_path: "/etc/sudoers.d" - state: present + user_groups: "{{ ([username, 'sudo'] + user_groups) | unique }}" - name: "Ensure user groups are created" become: true -- cgit v1.2.3