---
- name: Ensure ipaserver_domain is set
  when: ipaserver_domain is not defined
  block:
  - name: Get Domain from server name
    ansible.builtin.set_fact:
      ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join('.') }}"
    when: "'fqdn' in ansible_facts"
  - name: Set Domain to 'ipa.test' if FQDN could not be retrieved.
    ansible.builtin.set_fact:
      ipaserver_domain: "ipa.test"
    when: "'fqdn' not in ansible_facts"

- name: Set ipaserver_realm.
  ansible.builtin.set_fact:
    ipaserver_realm: "{{ ipaserver_domain | upper }}"
  when: ipaserver_realm is not defined

- name: Create FQDN for host01
  ansible.builtin.set_fact:
    host1_fqdn: "host01.{{ ipaserver_domain }}"
    host2_fqdn: "host02.{{ ipaserver_domain }}"
