---

- name: Validate FreeIPA Admin password was passed
  fail: msg="freeipa_admin_password is not passed and or blank"
  when:
    - deploy_supplemental_node|bool and not hostvars['supplemental'].freeipa_admin_password|default('')
    - not freeipa_admin_password|default('')

- name: Validate FreeIPA Server hostname was passed
  fail: msg="freeipa_server_hostname is not passed and or blank"
  when: freeipa_server_hostname is not defined or ( freeipa_server_hostname is defined and freeipa_server_hostname == "" )

- name: Validate a domain for the cloud was given
  fail: msg="overcloud_cloud_domain is not passed and or blank"
  when: overcloud_cloud_domain is not defined or ( overcloud_cloud_domain is defined and overcloud_cloud_domain == "" )

- name: Validate a undercloud hostname was given
  fail: msg="undercloud_undercloud_hostname is not passed and or blank"
  when: undercloud_undercloud_hostname is not defined or ( undercloud_undercloud_hostname is defined and undercloud_undercloud_hostname == "" )

- name: Install novajoin package installation script
  template:
    src: install_novajoin.sh.j2
    dest: "{{ working_dir }}/install_novajoin.sh"
    mode: 0755

- name: Run the novajoin installation script
  shell: >
    set -o pipefail &&
    {{ working_dir }}/install_novajoin.sh 2>&1 {{ timestamper_cmd }} >
    {{ working_dir }}/install_novajoin.sh.log

- name: Install novajoin preparation script
  template:
    src: novajoin_prep.sh.j2
    dest: "{{ working_dir }}/novajoin_prep.sh"
    mode: 0755

- name: Run the novajoin preparation script
  shell: >
    set -o pipefail &&
    {{ working_dir }}/novajoin_prep.sh 2>&1 {{ timestamper_cmd }} >
    {{ working_dir }}/novajoin_prep.sh.log

- name: Register OTP output
  command: cat {{ freeipa_otp_key }}
  register: ipa_otp_register

- name: Set OTP Fact for undercloud enrollment
  set_fact:
    undercloud_ipa_otp: "{{ ipa_otp_register.stdout }}"
  when: ipa_otp_register.rc == 0
