---
-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Checking if HTMO is enabled"
      register: htmo_installed_check
      ansible.builtin.stat:
        path: "{{ completed_dir }}/htmo_installed"
        get_md5: false
    
    -
      name: "Setting up Traveler HTMO"
      when: not htmo_installed_check.stat.exists
      block:
        -
          name: "Handing HTMO templated JSON to Genesis"
          ansible.builtin.template:
            dest: "{{ domino_home_dir }}/JavaAddin/Genesis/json/htmo-traveler-access.json"
            mode: "a+x"
            owner: "{{ domino_user }}"
            group: "{{ domino_group }}"
            src: "htmo-traveler-access.json.j2"

        -
          name: Waiting until Genesis returns OK
          ansible.builtin.wait_for:
            path: "{{ domino_home_dir }}/JavaAddin/Genesis/jsonresponse/htmo-traveler-access.json"

        -
          name: "Checking if ACL applied succesfully"
          ansible.builtin.lineinfile:
            path: "{{ domino_home_dir }}/JavaAddin/Genesis/jsonresponse/htmo-traveler-access.json"
            line: "OK"
            state: present
          check_mode: true
          register: presence_htmo
          failed_when: presence_htmo is changed

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

        -
          name: "Waiting for 30 seconds to let Domino fully shutdown"
          ansible.builtin.pause:
            seconds: "{{ domino_shutdown_delay }}"

        -
          name: "Starting Domino for Changes to take effect"
          become: true
          ansible.builtin.service:
            name: domino
            state: started
            enabled: true
          register: domino_service_start_details_htmo
          until: domino_service_start_details_htmo.state == "started"
          retries: 10
          delay: 10

        -
          name: "Waiting for HTTP Server to start"
          ansible.builtin.wait_for:
            path: /local/notesdata/IBM_TECHNICAL_SUPPORT/console.log
            search_regex: "HTTP Server: Started"
            timeout: 300
            msg: "HTTP Server did not start within the timeout period."

        -
          name: "Waiting for 60 seconds to let HTTP to fully startup"
          ansible.builtin.pause:
            seconds: "{{ domino_startup_delay }}"

        -
          name: "Marking HTMO as installed"
          ansible.builtin.file:
            mode: '0644'
            path: "{{ item }}"
            state: touch
          with_items:
            - "{{ completed_dir }}/htmo_installed"
