---
-
  name: "Creating Installation Directories"
  ansible.builtin.file:
    mode: '0644'
    path: "{{ item }}"
    state: directory
    owner: "{{ domino_user }}"
    group: "{{ domino_group }}"
  with_items:
    - "{{ installer_dir }}/domino/service-file"

-
  name: "Checking if Nash's Domino Service Scripts has been installed"
  register: domino_server_nash_installed
  ansible.builtin.stat:
    path: "{{ completed_dir }}/service_configured"
    get_md5: false

-
  name: "Downloading Nash's Service Script for Linux version {{ nash_domino_service_script_version }}"
  when: not domino_server_nash_installed.stat.exists
  register: nashresult
  until: "nashresult is not failed"
  retries: 3
  ansible.builtin.get_url:
    mode: '0644'
    url: "{{ nash_domino_service_script_git_repo }}/v{{ nash_domino_service_script_version }}/domino-startscript_v{{ nash_domino_service_script_version }}.taz"
    dest: "{{ installer_dir }}/domino/archives/domino-startscript_v{{ nash_domino_service_script_version }}.tar"

-
  name: "Extracting Domino Service file Installer"
  when: not domino_server_nash_installed.stat.exists
  ansible.builtin.unarchive:
    src: "{{ installer_dir }}/domino/archives/domino-startscript_v{{ nash_domino_service_script_version }}.tar"
    dest: "{{ installer_dir }}/domino/service-file"
    remote_src: true
    creates: "{{ completed_dir }}/service_configured and not domino_server_nash_installed.stat.exists"

-
  name: "Changing Nash's service installer script's default Datadir"
  when: not domino_server_nash_installed.stat.exists
  ansible.builtin.replace:
    path: "{{ installer_dir }}/domino/service-file/domino-startscript/sysconfig/rc_domino_config"
    regexp: "(^DOMINO_DATA_PATH=)(.*)$"
    replace: "DOMINO_DATA_PATH={{ domino_home_dir }}"

-
  name: "Changing Nash's service installer script's default User"
  when: not domino_server_nash_installed.stat.exists
  ansible.builtin.replace:
    path: "{{ installer_dir }}/domino/service-file/domino-startscript/install_script"
    regexp: "(^  DOMINO_USER=notes)(.*)$"
    replace: "  DOMINO_USER={{ domino_user }}"

-
  name: "Changing Nash's service installer script's default Domino Group"
  when: not domino_server_nash_installed.stat.exists
  ansible.builtin.replace:
    path: "{{ installer_dir }}/domino/service-file/domino-startscript/install_script"
    regexp: "(^  DOMINO_GROUP=notes)(.*)$"
    replace: "  DOMINO_GROUP={{ domino_group }}"

-
  name: "Configuring Domino systemd service file"
  when: not domino_server_nash_installed.stat.exists
  ansible.builtin.shell: "{{ item }}"
  become: true
  args:
    chdir: "{{ installer_dir }}/domino/service-file/domino-startscript"
    executable: "/bin/bash"
    creates: "{{ completed_dir }}/service_configured"
  with_items:
    - "./install_script"

-
  name: "Marking Nash Systemd Service as installed"
  when: not domino_server_nash_installed.stat.exists
  ansible.builtin.file:
    mode: '0644'
    path: "{{ item }}"
    state: touch
  with_items:
    - "{{ completed_dir }}/service_configured"

-
  name: "Ensuring Domino is stopped but enabled at boot"
  become: true
  ansible.builtin.service:
    name: domino
    state: stopped
    enabled: true
