From cd7ef92fb4a30113767482870496a04cac96bdf5 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 23 Mar 2023 11:30:52 +0200 Subject: [PATCH] Do not try to run useradd/groupadd if mash_playbook_uid/mash_playbook_gid explicitly specified Certain environments (like https://libreelec.tv/) do not have `useradd`/`groupadd` tools, so it's important to be able to avoid calling them, especially for no good reason. --- roles/mash/playbook_base/tasks/setup_user.yml | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/roles/mash/playbook_base/tasks/setup_user.yml b/roles/mash/playbook_base/tasks/setup_user.yml index 119f09e..9ec1790 100644 --- a/roles/mash/playbook_base/tasks/setup_user.yml +++ b/roles/mash/playbook_base/tasks/setup_user.yml @@ -1,24 +1,26 @@ --- -- name: Ensure mash group is created - ansible.builtin.group: - name: "{{ mash_playbook_user_groupname }}" - gid: "{{ omit if mash_playbook_gid is none else mash_playbook_gid }}" - state: present - register: mash_base_group_result +- when: not mash_playbook_uid and not mash_playbook_uid + block: + - name: Ensure mash group is created + ansible.builtin.group: + name: "{{ mash_playbook_user_groupname }}" + gid: "{{ omit if mash_playbook_gid is none else mash_playbook_gid }}" + state: present + register: mash_base_group_result -- name: Ensure mash user is created - ansible.builtin.user: - name: "{{ mash_playbook_user_username }}" - uid: "{{ omit if mash_playbook_uid is none else mash_playbook_uid }}" - state: present - group: "{{ mash_playbook_user_groupname }}" - home: "{{ mash_playbook_base_path }}" - create_home: false - system: true - register: mash_base_user_result + - name: Ensure mash user is created + ansible.builtin.user: + name: "{{ mash_playbook_user_username }}" + uid: "{{ omit if mash_playbook_uid is none else mash_playbook_uid }}" + state: present + group: "{{ mash_playbook_user_groupname }}" + home: "{{ mash_playbook_base_path }}" + create_home: false + system: true + register: mash_base_user_result -- name: Initialize mash_playbook_uid and mash_playbook_gid - ansible.builtin.set_fact: - mash_playbook_uid: "{{ mash_base_user_result.uid }}" - mash_playbook_gid: "{{ mash_base_group_result.gid }}" + - name: Initialize mash_playbook_uid and mash_playbook_gid + ansible.builtin.set_fact: + mash_playbook_uid: "{{ mash_base_user_result.uid }}" + mash_playbook_gid: "{{ mash_base_group_result.gid }}"