---
-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Checking if Genesis is installed: {{ genesis_version }}"
      register: genesis_installed_check
      ansible.builtin.stat:
        path: "{{ completed_dir }}/genesis_installed_check"
        get_md5: false
    
    -
      name: "Installing Genesis"
      when: not genesis_installed_check.stat.exists
      block:
        -
          name: "Creating installation directories for Genesis"
          ansible.builtin.file:
            mode: '0755'
            path: "{{ item }}"
            state: directory
            owner: "{{ domino_user }}"
            group: "{{ domino_group }}"
          with_items:
            - "{{ domino_home_dir }}/JavaAddin/Genesis"
            - "{{ domino_home_dir }}/JavaAddin/Genesis/json"

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

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

        -
          name: "Placing Genesis jar into the JavaAddin folder"
          become: true
          ansible.builtin.copy:
            mode: '0755'
            dest: "{{ domino_home_dir }}/JavaAddin/Genesis/{{ genesis_jar }}"
            owner: "{{ domino_user }}"
            group: "{{ domino_group }}"
            src: "{{ genesis_jar }}"

        -
          name: "Starting Domino for Changes to take effect"
          become: true
          ansible.builtin.service:
            name: domino
            state: started
            enabled: true
          register: domino_service_start_details_genesis
          until: domino_service_start_details_genesis.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: "Debug"
          when: ( genesis_debug or debug_all )
          ansible.builtin.debug:
            var: domino_service_start_details_genesis

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