---
-
  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: "Handing HTMO templated JSON to Genesis"
      when: not htmo_installed_check.stat.exists
      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
      when: not htmo_installed_check.stat.exists
      ansible.builtin.wait_for:
        path: "{{ domino_home_dir }}/JavaAddin/Genesis/jsonresponse/htmo-traveler-access.json"
    
    -
      name: "Checking if ACL applied succesfully"
      when: not htmo_installed_check.stat.exists
      ansible.builtin.lineinfile:
        path: "{{ domino_home_dir }}/JavaAddin/Genesis/jsonresponse/htmo-traveler-access.json"
        line: "OK"
        state: present
      check_mode: true
      register: presence
      failed_when: presence is changed
    
    -
      name: "Stopping Domino for Changes to take effect"
      when: not htmo_installed_check.stat.exists
      become: true
      ansible.builtin.service:
        name: domino
        state: stopped
        enabled: true
      register: domino_html_service_details_stop
      until: domino_html_service_details_stop.state == "stopped"
      retries: 3
      delay: 5
    
    -
      name: "Starting Domino for Changes to take effect"
      when: not htmo_installed_check.stat.exists
      ansible.builtin.service:
        name: domino
        state: started
        enabled: true
      register: domino_html_service_details_start
      retries: 3
      delay: 5
      until: domino_html_service_details_start.state == "started"
    
    -
      name: "Marking HTMO as installed"
      when: not htmo_installed_check.stat.exists
      ansible.builtin.file:
        mode: '0644'
        path: "{{ item }}"
        state: touch
      with_items:
        - "{{ completed_dir }}/htmo_installed"
