--- /dev/null
+---
+
+- name: 'Get the current configuration of the account-policy Plugin.'
+ ansible.builtin.shell: "dsconf {{ slapd_instance | quote }} plugin account-policy show | \
+ grep -P -i '^(nsslapd-pluginEnabled|nsslapd-pluginarg0)' | \
+ sed -e 's/nsslapd-plugin//i' -e 's/Enabled/enabled/i' | sort || true"
+ register: get_plugin_account_policy
+ changed_when: false
+ check_mode: false
+
+- name: 'Show raw account-policy attribute config.'
+ debug:
+ var: get_plugin_account_policy
+ verbosity: 2
+
+- name: "Set variable plugin_account_policy_config"
+ set_fact:
+ plugin_account_policy_config: "{{ get_plugin_account_policy.stdout_lines | cfg_389ds_to_dict }}"
+
+- name: "Set variable acc_plugin_entry."
+ set_fact:
+ acc_plugin_entry: "{{ plugin_account_policy_config['arg0'] }}"
+
+- name: "The account-policy Plugin entry:"
+ debug:
+ var: acc_plugin_entry
+ verbosity: 1
+
+- name: 'Get the current configuration entry of the account-policy Plugin.'
+ ansible.builtin.shell: "dsconf {{ slapd_instance | quote }} plugin account-policy config-entry show \
+ {{ plugin_account_policy_config['arg0'] | quote }} | \
+ grep -P -v -i '^([cd]n|objectClass):' | grep -v -P '^\\s*$' | sort -i || true"
+ register: get_plugin_account_policy_entry
+ changed_when: false
+ check_mode: false
+
+- name: 'Show raw account-policy attribute config entry.'
+ debug:
+ var: get_plugin_account_policy_entry
+ verbosity: 2
+
+- name: "Set variable plugin_account_policy_config_entry"
+ set_fact:
+ plugin_account_policy_config_entry: "{{ get_plugin_account_policy_entry.stdout_lines | cfg_389ds_to_dict }}"
+
+- name: "Set variable acc_plugin_cfg"
+ set_fact:
+ acc_plugin_cfg: "{{ plugin_account_policy_config | ansible.builtin.combine(plugin_account_policy_config_entry, list_merge='append_rp', recursive=true) }}"
+
+- name: "The account-policy Plugin configuration:"
+ debug:
+ var: acc_plugin_cfg
+ verbosity: 0
+
+- name: 'Predefine variables'
+ set_fact:
+ exec_set: false
+ attrs_remove: []
+
+- name: 'Check for alwaysrecordlogin'
+ set_fact:
+ exec_set: true
+ when: "('alwaysrecordlogin' not in acc_plugin_cfg) or (acc_plugin_cfg['alwaysrecordlogin'] != ds389_plugin_account_policy_always_record_login)"
+
+- 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 == '')"
+
+- 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))"
+
+- name: 'Check for always-record-login-attr for vanishing'
+ set_fact:
+ attrs_remove: "{{ always-record-login-attr + ['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 == '')"
+
+- 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))"
+
+# Failing: --limit-attr --spec-attr --state-attr --login-history-size --check-all-state-attrs
+
+- name: 'Setting new configuration for account-policy Plugin'
+ when: exec_set == true
+ block:
+
+ - name: "Init + set var plugin_acc_policy_cmd + restart_389ds."
+ set_fact:
+ plugin_acc_policy_cmd: "dsconf {{ slapd_instance | quote }} plugin account-policy config-entry set"
+ restart_389ds: true
+
+ - name: "Add --always-record-login to command."
+ set_fact:
+ plugin_acc_policy_cmd: "{{ plugin_acc_policy_cmd }} --always-record-login {{ ds389_plugin_account_policy_always_record_login | bool_to_yes_no }}"
+
+ - name: "Add --alt-state-attr to command."
+ set_fact:
+ plugin_acc_policy_cmd: "{{ plugin_acc_policy_cmd }} --alt-state-attr {{ ds389_plugin_account_policy_alt_state_attr | quote }}"
+ when: ds389_plugin_account_policy_alt_state_attr != None and ds389_plugin_account_policy_alt_state_attr != ''
+
+ - name: "Add --always-record-login-attr to command."
+ set_fact:
+ plugin_acc_policy_cmd: "{{ plugin_acc_policy_cmd }} --always-record-login-attr {{ ds389_plugin_account_policy_always_record_login_attr | quote }}"
+ when: ds389_plugin_account_policy_always_record_login_attr != None and ds389_plugin_account_policy_always_record_login_attr != ''
+
+ - name: "Add config DN to plugin_acc_policy_cmd."
+ set_fact:
+ plugin_acc_policy_cmd: "{{ plugin_acc_policy_cmd }} {{ acc_plugin_entry | quote }}"
+
+ - name: "Show the command to execute:"
+ debug:
+ var: plugin_acc_policy_cmd
+ verbosity: 0
+
+
+# vim: filetype=yaml