Make domjoin user and password configurable via inventory and join domain only when necessary

This commit is contained in:
Raphael Dannecker 2025-12-15 11:52:07 +01:00
parent c53e43f4ce
commit 37b8b94c9d
2 changed files with 19 additions and 6 deletions

View file

@ -0,0 +1,2 @@
---
sssd_domjoin_user: global-admin

View file

@ -13,12 +13,23 @@
mode: '0600' mode: '0600'
notify: Restart sssd notify: Restart sssd
## Either one of the variables is defined: - name: Check if the machine account password and the join are still valid
ansible.builtin.shell:
cmd: adcli testjoin -D {{ domain | upper }}
register: adcli_test_result
failed_when: false
changed_when: false
# If domjoin not valid:
- name: Join the domain - name: Join the domain
ansible.builtin.shell: ansible.builtin.shell:
cmd: > cmd: >
echo "{{ ansible_cmdline.adpw | default('') + adpw.user_input | default('') }}" | echo "{{ ad_passwd }}" | adcli join --stdin-password -U {{ ad_user }} {{ domain | upper }}
adcli join --stdin-password -U global-admin {{ domain | upper }} no_log: true
when: > vars:
ansible_cmdline.adpw | default('') | length > 0 or - ad_user: "{{ 'global-admin' if (adpw.user_input | default(ansible_cmdline.adpw) | default('') | length > 0) else sssd_domjoin_user }}"
adpw.user_input | default('') | length > 0 - ad_passwd: "{{ adpw.user_input | default('') if adpw.user_input | length > 0 else ansible_cmdline.adpw | default(sssd_domjoin_passwd) | default('') }}"
when:
- adpw.user_input | length > 0 or
ansible_cmdline.adpw | default(sssd_domjoin_passwd) | default('') | length > 0
- adcli_test_result.rc != 0