From 4da37ae51a45252e60fbdf7e2323bd16426153ce Mon Sep 17 00:00:00 2001 From: Michael Grote Date: Tue, 8 Oct 2024 16:33:28 +0200 Subject: [PATCH] dd --- group_vars/all.yml | 8 ++++++-- roles/mgrote_users/tasks/main.yml | 12 +++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/group_vars/all.yml b/group_vars/all.yml index 8e05f536..54bfcdb1 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -27,7 +27,9 @@ users: - username: mg password: "{{ lookup('viczem.keepass.keepass', 'mg_linux_password_hash', 'password') }}" update_password: always - groups: ssh, sudo + groups: + - ssh + - sudo state: present public_ssh_key: "{{ ssh_public_key_mg }}" allow_sudo: true @@ -35,7 +37,9 @@ users: - username: ansible-user password: "{{ lookup('viczem.keepass.keepass', 'ansible_user_linux_password_hash', 'password') }}" update_password: always - groups: ssh, sudo + groups: + - ssh + - sudo state: present public_ssh_key: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJcBwOjanQV6sFWaTetqpl20SVe3aRzGjKbsp7hKkDCE mg@irantu allow_sudo: true diff --git a/roles/mgrote_users/tasks/main.yml b/roles/mgrote_users/tasks/main.yml index e7a76f47..0a8032de 100644 --- a/roles/mgrote_users/tasks/main.yml +++ b/roles/mgrote_users/tasks/main.yml @@ -1,16 +1,10 @@ --- -- name: set groups as list - ansible.builtin.set_fact: - groups_as_list: "{{ (((((groups_as_list | default([]) + item.groups.split(','))) | map('trim')) | list) | sort) | unique }}" - loop: '{{ users }}' - when: item.groups is defined - - name: create groups ansible.builtin.group: - name: "{{ item }}" + name: "{{ ((item.groups) | sort) | unique }}" state: present - loop: "{{ groups_as_list }}" - when: groups_as_list is defined + loop: '{{ users }}' + when: item.groups is defined - name: create users ansible.builtin.user: