---
-
  name: "Ensuring Domino is up"
  ansible.builtin.service:
    name: domino
    state: started
    enabled: true

-
  name: "Checking if ID to Cross Certify is available at /safe-id-to-cross-certify/{{ safe_notes_id }}"
  register: cross_certify_check
  ansible.builtin.stat:
    path: "/safe-id-to-cross-certify/{{ safe_notes_id }}"
    get_md5: false

-
  name: Pause for 45 seconds to let Domino fully start
  when: cross_certify_check.stat.exists
  ansible.builtin.pause:
    seconds: 45

-
  name: "Cross Certifying /safe-id-to-cross-certify/{{ safe_notes_id }}"
  become_user: "{{ service_user }}"
  become: true
  register: cross_certify_commands
  when: cross_certify_check.stat.exists
  ansible.builtin.shell: >
    source {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh &&
    source {{ service_home_dir }}/.bashrc &&
    source {{ service_home_dir }}/.bash_profile &&
    $JAVA_HOME/bin/java
    -Dapp.properties.file={{ service_home_dir }}/CrossCertifyNotesID.properties
    -jar CrossCertifyNotesID.jar /safe-id-to-cross-certify/{{ safe_notes_id }}
  args:
    executable: /bin/bash
    chdir: "{{ service_home_dir }}"

-
  name: "Waiting until the Cross Certification JAR writes to CrossCertifyNotesID.out"
  when: cross_certify_check.stat.exists
  ansible.builtin.wait_for:
    path: "{{ completed_dir }}/CrossCertifyNotesID.out"

-
  name: "Outputting available Help Text"
  when: cross_certify_check.stat.exists
  ansible.builtin.debug:
    var: cross_certify_commands.stdout_lines

-
  name: "Running Check database to populate IDs into ID Vault"
  become_user: "{{ service_user }}"
  ansible.builtin.expect:
    chdir: "{{ service_home_dir }}"
    command: >
      /bin/bash -c "
        . {{ service_home_dir }}/.bash_profile &&
        . {{ service_home_dir }}/.bashrc &&
        . {{ service_home_dir }}/.sdkman/bin/sdkman-init.sh &&
        java -jar CheckDatabase.jar {{ settings.hostname }}.{{ settings.domain }}/{{ domino_organization }} names.nsf"
    responses:
      'Enter password \(press the Esc key to abort\): ': "{{ domino_admin_notes_id_password }}"

-
  name: "Stopping Domino for Changes to take effect"
  become: true
  when: cross_certify_check.stat.exists
  ansible.builtin.service:
    name: domino
    state: stopped
    enabled: true
  register: domino_cc_service_details_stop
  until: domino_cc_service_details_stop.state == "stopped"
  retries: 3
  delay: 5

-
  name: "Starting Domino for Changes to take effect"
  when: cross_certify_check.stat.exists
  ansible.builtin.service:
    name: domino
    state: started
    enabled: true
  register: domino_cc_service_details_start
  retries: 3
  delay: 5
  until: domino_cc_service_details_start.state == "started"
