From 05c7df5693906f6867106cd71727317cf9be0f8b Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Mon, 9 May 2022 11:02:35 +0200 Subject: [PATCH] fix: create users und groups only if defined --- tasks/main.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index d5abcd4..77ae886 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,25 +5,41 @@ with_dict: "{{ unix_groups }}" loop_control: loop_var: unix_group - when: unix_group.value.state is defined and unix_group.value.state == 'absent' + when: unix_groups is defined and + unix_groups | length > 0 and + unix_group.value.state is defined and + unix_group.value.state == 'absent' - name: Remove unix user include_tasks: remove_unix_user.yml with_dict: "{{ unix_users }}" loop_control: loop_var: unix_user - when: unix_user.value.state is defined and unix_user.value.state == 'absent' + when: unix_groups is defined and + unix_groups | length > 0 and + unix_user.value.state is defined and + unix_user.value.state == 'absent' - name: Create unix groups include_tasks: create_unix_group.yml with_dict: "{{ unix_groups }}" loop_control: loop_var: unix_group - when: unix_group.value.state is defined and unix_group.value.state == 'present' or unix_group.value.state is not defined + when: unix_groups is defined and + unix_groups | length > 0 and + ( + (unix_group.value.state is defined and unix_group.value.state == 'present') or + unix_group.value.state is not defined + ) - name: Create unix users include_tasks: create_unix_user.yml with_dict: "{{ unix_users }}" loop_control: loop_var: unix_user - when: unix_user.value.state is defined and unix_user.value.state == 'present' or unix_user.value.state is not defined + when: unix_groups is defined and + unix_groups | length > 0 and + ( + (unix_user.value.state is defined and unix_user.value.state == 'present') or + unix_user.value.state is not defined + )