From 5d6ba322572624701bfd05378429338e4ab586b5 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 12 Dec 2024 14:10:24 +0100 Subject: [PATCH] Using the test-plugin function 'empty' --- roles/389ds-check-initial/tasks/main.yaml | 8 +++--- .../tasks/config-facility.yaml | 2 +- .../tasks/account-policy.yaml | 28 +++++++++---------- .../tasks/attr-uniq-entry-add.yaml | 6 ++-- .../tasks/attr-uniq-entry-modify.yaml | 20 ++++++------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/roles/389ds-check-initial/tasks/main.yaml b/roles/389ds-check-initial/tasks/main.yaml index 1878d62..c29caee 100644 --- a/roles/389ds-check-initial/tasks/main.yaml +++ b/roles/389ds-check-initial/tasks/main.yaml @@ -21,7 +21,7 @@ - name: "Fail for non existing 389ds LDAP server." ansible.builtin.fail: msg: "No 389ds LDAP server found on host '{{ inventory_hostname }}'." - when: version_389ds == '' + when: version_389ds is empty - name: "Get the list of available Directory Server instances." ansible.builtin.shell: "dsctl --list | sed -e 's/^slapd-//'" @@ -41,10 +41,10 @@ - name: "Fail, if there are no running Directory Server instances." ansible.builtin.fail: msg: "No Directory Server instances found on host '{{ inventory_hostname }}'." - when: instances_389ds | length < 1 + when: instances_389ds is empty - name: "Retrieve the slapd instance name, if not given." - when: slapd_instance is not defined + when: slapd_instance is empty block: - name: "Set slapd_instance to the first found instance, because it was not given." @@ -96,6 +96,6 @@ - name: 'Got no admin password' ansible.builtin.fail: msg: "Did not found a password in file {{ dirsrv_root_passwd_file || quote }}." - when: dirsrv_root_passwd == '' + when: dirsrv_root_passwd is empty # vim: filetype=yaml diff --git a/roles/389ds-config-logging/tasks/config-facility.yaml b/roles/389ds-config-logging/tasks/config-facility.yaml index e44feb3..03fc655 100644 --- a/roles/389ds-config-logging/tasks/config-facility.yaml +++ b/roles/389ds-config-logging/tasks/config-facility.yaml @@ -12,7 +12,7 @@ verbosity: 3 - name: "Generate config hash." - when: config_get.stdout != "" + when: config_get.stdout is not empty block: - name: "Set logging variables" diff --git a/roles/389ds-config-plugins/tasks/account-policy.yaml b/roles/389ds-config-plugins/tasks/account-policy.yaml index 3e17144..4546546 100644 --- a/roles/389ds-config-plugins/tasks/account-policy.yaml +++ b/roles/389ds-config-plugins/tasks/account-policy.yaml @@ -65,72 +65,72 @@ - name: 'Check for alt-state-attr for vanishing' set_fact: attrs_remove: "{{ alt-state-attr + ['altstateattrname']" - when: "('altstateattrname' in acc_plugin_cfg) and (ds389_plugin_account_policy_alt_state_attr == None or ds389_plugin_account_policy_alt_state_attr == '')" + when: "('altstateattrname' in acc_plugin_cfg) and ds389_plugin_account_policy_alt_state_attr is empty" - name: 'Check for alt-state-attr' set_fact: exec_set: true - when: "ds389_plugin_account_policy_alt_state_attr != None and ds389_plugin_account_policy_alt_state_attr != '' and ('altstateattrname' not in acc_plugin_cfg or (acc_plugin_cfg['altstateattrname'] != ds389_plugin_account_policy_alt_state_attr))" + when: "ds389_plugin_account_policy_alt_state_attr is not empty and ('altstateattrname' not in acc_plugin_cfg or (acc_plugin_cfg['altstateattrname'] != ds389_plugin_account_policy_alt_state_attr))" - name: 'Check for always-record-login-attr for vanishing' set_fact: attrs_remove: "{{ attrs_remove + ['alwaysrecordloginattr']" - when: "('alwaysrecordloginattr' in acc_plugin_cfg) and (ds389_plugin_account_policy_always-record-login-attr == None or ds389_plugin_account_policy_always-record-login-attr == '')" + when: "('alwaysrecordloginattr' in acc_plugin_cfg) and ds389_plugin_account_policy_always-record-login-attr is empty" - name: 'Check for always-record-login-attr' set_fact: exec_set: true - when: "ds389_plugin_account_policy_always_record_login_attr != None and ds389_plugin_account_policy_always_record_login_attr != '' and ('alwaysrecordloginattr' not in acc_plugin_cfg or (acc_plugin_cfg['alwaysrecordloginattr'] != ds389_plugin_account_policy_always_record_login_attr))" + when: "ds389_plugin_account_policy_always_record_login_attr is not empty ('alwaysrecordloginattr' not in acc_plugin_cfg or (acc_plugin_cfg['alwaysrecordloginattr'] != ds389_plugin_account_policy_always_record_login_attr))" - name: 'Check limit-attr for vanishing' set_fact: attrs_remove: "{{ attrs_remove + ['limitattrname'] }}" - when: "('limitattrname' in acc_plugin_cfg) and (ds389_plugin_account_policy_limit_attr == None or ds389_plugin_account_policy_limit_attr == '')" + when: "('limitattrname' in acc_plugin_cfg) and ds389_plugin_account_policy_limit_attr is empty" - name: 'Check limit-attr' set_fact: exec_set: true - when: "ds389_plugin_account_policy_limit_attr != None and ds389_plugin_account_policy_limit_attr != '' and ('limitattrname' not in acc_plugin_cfg or ((acc_plugin_cfg['limitattrname'] | lower) != (ds389_plugin_account_policy_limit_attr | lower)))" + when: "ds389_plugin_account_policy_limit_attr is not empty and ('limitattrname' not in acc_plugin_cfg or ((acc_plugin_cfg['limitattrname'] | lower) != (ds389_plugin_account_policy_limit_attr | lower)))" - name: 'Check spec-attr for vanishing' set_fact: attrs_remove: "{{ attrs_remove + ['specattrname'] }}" - when: "('specattrname' in acc_plugin_cfg) and (ds389_plugin_account_policy_spec_attr == None or ds389_plugin_account_policy_spec_attr == '')" + when: "('specattrname' in acc_plugin_cfg) and ds389_plugin_account_policy_spec_attr is empty" - name: 'Check spec-attr' set_fact: exec_set: true - when: "ds389_plugin_account_policy_spec_attr != None and ds389_plugin_account_policy_spec_attr != '' and ('specattrname' not in acc_plugin_cfg or ((acc_plugin_cfg['specattrname'] | lower) != (ds389_plugin_account_policy_spec_attr | lower)))" + when: "ds389_plugin_account_policy_spec_attr is not empty and ('specattrname' not in acc_plugin_cfg or ((acc_plugin_cfg['specattrname'] | lower) != (ds389_plugin_account_policy_spec_attr | lower)))" - name: 'Check state-attr for vanishing' set_fact: attrs_remove: "{{ attrs_remove + ['stateattrname'] }}" - when: "('stateattrname' in acc_plugin_cfg) and (ds389_plugin_account_policy_state_attr == None or ds389_plugin_account_policy_state_attr == '')" + when: "('stateattrname' in acc_plugin_cfg) and ds389_plugin_account_policy_state_attr is empty" - name: 'Check state-attr' set_fact: exec_set: true - when: "ds389_plugin_account_policy_state_attr != None and ds389_plugin_account_policy_state_attr != '' and ('stateattrname' not in acc_plugin_cfg or ((acc_plugin_cfg['stateattrname'] | lower) != (ds389_plugin_account_policy_state_attr | lower)))" + when: "ds389_plugin_account_policy_state_attr is not empty and ('stateattrname' not in acc_plugin_cfg or ((acc_plugin_cfg['stateattrname'] | lower) != (ds389_plugin_account_policy_state_attr | lower)))" - name: 'Check login-history-size for vanishing' set_fact: attrs_remove: "{{ attrs_remove + ['lastloginhistsize'] }}" - when: "('lastloginhistsize' in acc_plugin_cfg) and (ds389_plugin_account_policy_login_history_size == None or ds389_plugin_account_policy_login_history_size == '')" + when: "('lastloginhistsize' in acc_plugin_cfg) and ds389_plugin_account_policy_login_history_size is empty" - name: 'Check login-history-size' set_fact: exec_set: true - when: "ds389_plugin_account_policy_login_history_size != None and ds389_plugin_account_policy_login_history_size != '' and ('lastloginhistsize' not in acc_plugin_cfg or (acc_plugin_cfg['lastloginhistsize'] != ds389_plugin_account_policy_login_history_size ))" + when: "ds389_plugin_account_policy_login_history_size is not empty and ('lastloginhistsize' not in acc_plugin_cfg or (acc_plugin_cfg['lastloginhistsize'] != ds389_plugin_account_policy_login_history_size ))" - name: 'Check check-all-state-attrs for vanishing' set_fact: attrs_remove: "{{ attrs_remove + ['checkallstateattrs'] }}" - when: "('checkallstateattrs' in acc_plugin_cfg) and (ds389_plugin_account_policy_check_all_state_attrs == None or ds389_plugin_account_policy_check_all_state_attrs == '')" + when: "('checkallstateattrs' in acc_plugin_cfg) and ds389_plugin_account_policy_check_all_state_attrs is empty" - name: 'Check check-all-state-attrs' set_fact: exec_set: true - when: "ds389_plugin_account_policy_check_all_state_attrs != None and ds389_plugin_account_policy_check_all_state_attrs != '' and (('checkallstateattrs' not in acc_plugin_cfg) or (acc_plugin_cfg['checkallstateattrs'] | bool) != (ds389_plugin_account_policy_check_all_state_attrs | bool))" + when: "ds389_plugin_account_policy_check_all_state_attrs is not empty and (('checkallstateattrs' not in acc_plugin_cfg) or (acc_plugin_cfg['checkallstateattrs'] | bool) != (ds389_plugin_account_policy_check_all_state_attrs | bool))" - name: "Task block for removing pointless config entries." when: attrs_remove | length > 0 diff --git a/roles/389ds-config-plugins/tasks/attr-uniq-entry-add.yaml b/roles/389ds-config-plugins/tasks/attr-uniq-entry-add.yaml index 5d29ec2..e667753 100644 --- a/roles/389ds-config-plugins/tasks/attr-uniq-entry-add.yaml +++ b/roles/389ds-config-plugins/tasks/attr-uniq-entry-add.yaml @@ -20,7 +20,7 @@ - name: "Adding subtrees to entry_add_cmd." set_fact: entry_add_cmd: "{{ entry_add_cmd }} --subtree {{ entry_data['subtrees'] | map('quote') | join(' ') }}" - when: "'subtrees' in entry_data and entry_data['subtrees'] | length > 0" + when: "'subtrees' in entry_data and entry_data['subtrees'] is not empty" - name: "Adding across_all_subtrees to entry_add_cmd." set_fact: @@ -29,12 +29,12 @@ - name: "Adding top_entry_oc to entry_add_cmd." set_fact: entry_add_cmd: "{{ entry_add_cmd }} --top-entry-oc {{ entry_data['top_entry_oc'] | quote }}" - when: "'top_entry_oc' in entry_data and entry_data['top_entry_oc'] is defined and entry_data['top_entry_oc'] != None and entry_data['top_entry_oc'] | length > 0" + when: "'top_entry_oc' in entry_data and entry_data['top_entry_oc'] is not empty" - name: "Adding subtree_entries_oc to entry_add_cmd." set_fact: entry_add_cmd: "{{ entry_add_cmd }} --subtree-entries-oc {{ entry_data['subtree_entries_oc'] | quote }}" - when: "'subtree_entries_oc' in entry_data and entry_data['subtree_entries_oc'] is defined and entry_data['subtree_entries_oc'] != None and entry_data['subtree_entries_oc'] | length > 0" + when: "'subtree_entries_oc' in entry_data and entry_data['subtree_entries_oc'] is not empty" - name: "Adding entry name to entry_add_cmd." set_fact: diff --git a/roles/389ds-config-plugins/tasks/attr-uniq-entry-modify.yaml b/roles/389ds-config-plugins/tasks/attr-uniq-entry-modify.yaml index b5793a1..3fa7416 100644 --- a/roles/389ds-config-plugins/tasks/attr-uniq-entry-modify.yaml +++ b/roles/389ds-config-plugins/tasks/attr-uniq-entry-modify.yaml @@ -47,7 +47,7 @@ - name: "Set remove_attr_uniq_entry_before to true in case of no subtrees expected." set_fact: remove_attr_uniq_entry_before: true - when: "'subtrees' in attr_uniq_config and ('subtrees' not in entry_data or entry_data['subtrees'] | length == 0)" + when: "'subtrees' in attr_uniq_config and ('subtrees' not in entry_data or entry_data['subtrees'] is empty)" - name: "Set cur_subtrees to an empty list, if none were found" set_fact: @@ -62,7 +62,7 @@ - name: "Check subtrees" set_fact: exec_set: true - when: "('subtrees' in entry_data and entry_data['subtrees'] | length > 0 ) and (cur_subtrees | compare_lc_list(entry_data['subtrees']) == false)" + when: "('subtrees' in entry_data and entry_data['subtrees'] is not empty ) and (cur_subtrees | compare_lc_list(entry_data['subtrees']) == false)" - name: "Check attribute name" set_fact: @@ -72,32 +72,32 @@ - name: "Check across-all-subtrees for should be vanished." set_fact: remove_attr_uniq_entry_before: true - when: "('across-all-subtrees' in attr_uniq_config) and ('across_all_subtrees' not in entry_data or entry_data['across_all_subtrees'] == None)" + when: "('across-all-subtrees' in attr_uniq_config) and ('across_all_subtrees' not in entry_data or entry_data['across_all_subtrees'] is empty)" - name: "Check across-all-subtrees" set_fact: exec_set: true - when: "'across_all_subtrees' in entry_data and entry_data['across_all_subtrees'] != None and ('across-all-subtrees' not in attr_uniq_config or entry_data['across_all_subtrees'] != attr_uniq_config['across-all-subtrees'])" + when: "'across_all_subtrees' in entry_data and entry_data['across_all_subtrees'] is not empty and ('across-all-subtrees' not in attr_uniq_config or entry_data['across_all_subtrees'] != attr_uniq_config['across-all-subtrees'])" - name: "Check top-entry-oc for should be vanished." set_fact: remove_attr_uniq_entry_before: true - when: "('top-entry-oc' in attr_uniq_config) and ('top_entry_oc' not in entry_data or entry_data['top_entry_oc'] == None)" + when: "('top-entry-oc' in attr_uniq_config) and ('top_entry_oc' not in entry_data or entry_data['top_entry_oc'] is empty)" - name: 'Check top-entry-oc' set_fact: exec_set: true - when: "('top_entry_oc' in entry_data) and (entry_data['top_entry_oc'] != None) and (('top-entry-oc' not in attr_uniq_config) or ((attr_uniq_config['top-entry-oc'] | lower) != (entry_data['top_entry_oc'] | lower)) )" + when: "('top_entry_oc' in entry_data) and (entry_data['top_entry_oc'] is not empty) and (('top-entry-oc' not in attr_uniq_config) or ((attr_uniq_config['top-entry-oc'] | lower) != (entry_data['top_entry_oc'] | lower)) )" - name: "Check subtree-entries-oc for should be vanished." set_fact: remove_attr_uniq_entry_before: true - when: "('subtree-entries-oc' in attr_uniq_config) and ('subtree_entries_oc' not in entry_data or entry_data['subtree_entries_oc'] == None)" + when: "('subtree-entries-oc' in attr_uniq_config) and ('subtree_entries_oc' not in entry_data or entry_data['subtree_entries_oc'] is empty)" - name: 'Check subtree-entries-oc' set_fact: exec_set: true - when: "('subtree_entries_oc' in entry_data) and (entry_data['subtree_entries_oc'] != None) and (('subtree-entries-oc' not in attr_uniq_config) or ((attr_uniq_config['subtree-entries-oc'] | lower) != (entry_data['subtree_entries_oc'] | lower)) )" + when: "('subtree_entries_oc' in entry_data) and (entry_data['subtree_entries_oc'] is not empty) and (('subtree-entries-oc' not in attr_uniq_config) or ((attr_uniq_config['subtree-entries-oc'] | lower) != (entry_data['subtree_entries_oc'] | lower)) )" - name: 'Actions for removing attr-uniq entry.' when: remove_attr_uniq_entry_before == true @@ -149,12 +149,12 @@ - name: "Adding top_entry_oc to entry_set_cmd." set_fact: entry_set_cmd: "{{ entry_set_cmd }} --top-entry-oc {{ entry_data['top_entry_oc'] | quote }}" - when: "'top_entry_oc' in entry_data and entry_data['top_entry_oc'] is defined and entry_data['top_entry_oc'] != None and entry_data['top_entry_oc'] | length > 0" + when: "'top_entry_oc' in entry_data and entry_data['top_entry_oc'] is not empty" - name: "Adding subtree_entries_oc to entry_set_cmd." set_fact: entry_set_cmd: "{{ entry_set_cmd }} --subtree-entries-oc {{ entry_data['subtree_entries_oc'] | quote }}" - when: "'subtree_entries_oc' in entry_data and entry_data['subtree_entries_oc'] is defined and entry_data['subtree_entries_oc'] != None and entry_data['subtree_entries_oc'] | length > 0" + when: "'subtree_entries_oc' in entry_data and entry_data['subtree_entries_oc'] is defined and entry_data['subtree_entries_oc'] is not empty" - name: "Adding entry name to entry_set_cmd." set_fact: -- 2.39.5