From c17fccec08689065c8f4f902544e984521c7437b Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 22 Apr 2024 19:53:43 +0200 Subject: revamp: user/group handling --- roles/core/users/tasks/main.yml | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 roles/core/users/tasks/main.yml (limited to 'roles/core/users/tasks/main.yml') diff --git a/roles/core/users/tasks/main.yml b/roles/core/users/tasks/main.yml new file mode 100644 index 00000000..43fe92f4 --- /dev/null +++ b/roles/core/users/tasks/main.yml @@ -0,0 +1,46 @@ +--- +- name: load os/distrubtion/version specific variables + include_vars: "{{ item }}" + with_first_found: + - files: + - "{{ ansible_distribution_release }}.yml" + - "{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}.yml" + +- name: load os/distrubtion/version specific tasks + vars: + params: + files: + - "{{ ansible_distribution_release }}.yml" + - "{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}.yml" + loop: "{{ q('first_found', params) }}" + loop_control: + loop_var: tasks_file + include_tasks: "{{ tasks_file }}" + +- name: add normal users + loop: "{{ normal_users | difference(admin_users) }}" + user: + name: "{{ item }}" + state: present + password: "{{ hostvars[inventory_hostname]['vault_user_password_'+item] }}" ## TODO: find nicer way to do this + shell: "{{ users[item].shell | default(admin_users_default_shell) }}" + +- name: add admin users + loop: "{{ admin_users }}" + user: + name: "{{ item }}" + state: present + password: "{{ hostvars[inventory_hostname]['vault_user_password_'+item] }}" ## TODO: find nicer way to do this + groups: "{{ admin_users_groups }}" + append: yes + shell: "{{ users[item].shell | default(admin_users_default_shell) }}" + +- name: install ssh keys for users + loop: "{{ normal_users | union(admin_users) }}" + when: "'ssh' in users[item]" + authorized_key: + user: "{{ item }}" + key: "{{ users[item].ssh | join('\n') }}" + exclusive: yes -- cgit v1.2.3