---
-
  name: "Creating Domino installation directories"
  ansible.builtin.file:
    mode: '0644'
    path: "{{ item }}"
    state: directory
  with_items:
    - "{{ installer_dir }}/domino"
    - "{{ installer_dir }}/domino/core"
    - "{{ installer_dir }}/domino/fixpack"
    - "{{ installer_dir }}/domino/hotfix"

-
  name: "Checking if the Domino Installer archive is at /domino/archives/{{ domino_server_installer_tar }}"
  register: domino_server_installer_check
  ansible.builtin.stat:
    path: "{{ installer_dir }}/domino/archives/{{ domino_server_installer_tar }}"
    get_md5: false

-
  name: "Checking if Domino has been installed"
  register: domino_server_installed
  ansible.builtin.stat:
    path: "{{ domino_home_dir }}/notes.ini"
    get_md5: false

-
  name: "Downloading Domino from {{ domino_installer_base_url }}"
  register: domlsresult
  until: "domlsresult is not failed"
  retries: 3
  ansible.builtin.get_url:
    mode: '0755'
    url: "{{ domino_installer_base_url }}/ND{{ domino_major_version }}/{{ domino_server_installer_tar }}"
    dest: "{{ installer_dir }}/domino/archives/{{ domino_server_installer_tar }}"
    username: "{{ domino_installer_url_user }}"
    password: "{{ secrets.domino_installer_url_pass }}"
  when: not domino_server_installer_check.stat.exists and not domino_server_installed.stat.exists

-
  name: "Extracting Domino from {{ domino_server_installer_tar }}"
  when: not domino_server_installed.stat.exists
  ansible.builtin.unarchive:
    src: "{{ installer_dir }}/domino/archives/{{ domino_server_installer_tar }}"
    dest: "{{ installer_dir }}/domino/core"
    creates: "{{ installer_dir }}/domino/core/linux64"
    remote_src: true

-
  name: "Checking if the Domino fixpack installer archive is at /domino/archives/{{ domino_server_fixpack_tar }}"
  register: fixpack_archive
  ansible.builtin.stat:
    path: "{{ installer_dir }}/domino/archives/{{ domino_server_fixpack_tar }}"
    get_md5: false

-
  name: "Checking if the Domino fixpack extracted installer is at /domino/fixpack/linux64"
  register: fixpack_extracted
  ansible.builtin.stat:
    path: "{{ installer_dir }}/domino/fixpack/linux64"
    get_md5: false

-
  name: "Checking if the Domino fixpack has been installed"
  register: fixpack_installed
  ansible.builtin.stat:
    path: "{{ completed_dir }}/fpinstalled"
    get_md5: false

-
  name: "Downloading Domino Fixpack from {{ domino_installer_base_url }}"
  register: fplsresult
  until: "fplsresult is not failed"
  retries: 3
  when: not fixpack_archive.stat.exists and not fixpack_extracted.stat.exists and not domino_installer_fixpack_install and fixpack_installed.stat.exists
  ansible.builtin.get_url:
    mode: '0755'
    url: "{{ domino_installer_base_url }}/ND{{ domino_major_version }}/{{ domino_server_fixpack_tar }}"
    dest: "{{ installer_dir }}/domino/archives/{{ domino_server_fixpack_tar }}"
    username: "{{ domino_installer_url_user }}"
    password: "{{ secrets.domino_installer_url_pass }}"

-
  name: "Extracting Domino fixpack from {{ domino_server_fixpack_tar }}"
  when: domino_installer_fixpack_install and not fixpack_extracted.stat.exists and not fixpack_installed.stat.exists
  ansible.builtin.unarchive:
    src: "{{ installer_dir }}/domino/archives/{{ domino_server_fixpack_tar }}"
    dest: "{{ installer_dir }}/domino/fixpack"
    creates: "{{ installer_dir }}/domino/fixpack/linux64"
    remote_src: true

-
  name: "Checking if the Domino hotfix installer archive is at /domino/archives/{{ domino_server_hotfix_tar }}"
  register: hotfix_installer_check
  ansible.builtin.stat:
    path: "{{ installer_dir }}/domino/archives/{{ domino_server_hotfix_tar }}"
    get_md5: false

-
  name: "Checking if the Domino hotfix extracted installer is at /domino/hotfix/domino"
  register: hotfix_extracted
  ansible.builtin.stat:
    path: "{{ installer_dir }}/domino/hotfix/domino"
    get_md5: false

-
  name: "Checking if the Domino hotfix has been installed"
  register: hotfix_installed
  ansible.builtin.stat:
    path: "{{ completed_dir }}/hfinstalled"
    get_md5: false

-
  name: "Downloading Domino hotfix from {{ domino_installer_base_url }}"
  register: hflsresult
  until: "hflsresult is not failed"
  retries: 3
  ansible.builtin.get_url:
    mode: '0755'
    url: "{{ domino_installer_base_url }}/ND{{ domino_major_version }}/{{ domino_server_hotfix_tar }}"
    dest: "{{ installer_dir }}/domino/archives/{{ domino_server_hotfix_tar }}"
    username: "{{ domino_installer_url_user }}"
    password: "{{ secrets.domino_installer_url_pass }}"
  when: not hotfix_installer_check.stat.exists and not hotfix_extracted.stat.exists and domino_installer_hotfix_install and not hotfix_installed.stat.exists

-
  name: "Extracting Domino Hotfix from {{ domino_server_hotfix_tar }}"
  when: domino_installer_hotfix_install and not hotfix_extracted.stat.exists and not hotfix_installed.stat.exists
  ansible.builtin.unarchive:
    src: "{{ installer_dir }}/domino/archives/{{ domino_server_hotfix_tar }}"
    dest: "{{ installer_dir }}/domino/hotfix"
    creates: "{{ installer_dir }}/domino/hotfix/domino"
    remote_src: true

-
  name: "Creating the group {{ domino_group }}"
  ansible.builtin.group:
    name: "{{ domino_group }}"
    state: present

-
  name: "Adding user group: {{ domino_group }}"
  ansible.builtin.user:
    name: "{{ domino_user }}"
    shell: /bin/sh
    groups: "{{ domino_group }}"
    home: "{{ domino_home_dir }}"

-
  name: "Adding soft nofile limits in limits.conf for: {{ domino_user }}"
  community.general.pam_limits:
    domain: "{{ domino_user }}"
    limit_type: soft
    limit_item: nofile
    value: "{{ domino_user_soft_limit }}"

-
  name: "Adding hard nofile limits to limits.conf for: {{ domino_user }}"
  community.general.pam_limits:
    domain: "{{ domino_user }}"
    limit_type: hard
    limit_item: nofile
    value: "{{ domino_user_hard_limit }}"

-
  name: "Adding Domino silent install response file"
  when: not domino_server_installed.stat.exists
  ansible.builtin.template:
    dest: "{{ installer_dir }}/domino/installer.properties"
    mode: a+x
    src: "installer.properties.j2"

-
  name: "Installing Domino"
  ansible.builtin.command: "{{ item }}"
  become: true
  become_user: root
  when: not domino_server_installed.stat.exists
  args:
    chdir: "{{ installer_dir }}/domino/core/linux64"
    creates: "{{ domino_home_dir }}/notes.ini"
  with_items:
    - "bash ./install -f {{ installer_dir }}/domino/installer.properties -i silent"

-
  name: "Configuring fixpack installer {{ domino_fixpack_version }}"
  when: domino_installer_fixpack_install and not fixpack_installed.stat.exists
  ansible.builtin.lineinfile:
    path: "{{ installer_dir }}/domino/fixpack/linux64/domino/script.dat"
    line: "installation_type = 2"

-
  name: "Installing Domino fixpack {{ domino_fixpack_version }}"
  ansible.builtin.command: "{{ item }}"
  become: true
  become_user: root
  environment:
    NUI_NOTESDIR: "{{ domino_install_basedir }}/"
  args:
    chdir: "{{ installer_dir }}/domino/fixpack/linux64/domino"
    creates: "{{ completed_dir }}/fpinstalled"
  when: domino_installer_fixpack_install and not fixpack_installed.stat.exists
  with_items:
    - "bash ./install -script ./script.dat && touch {{ completed_dir }}/fpinstalled"

-
  name: "Configuring hotfix installer {{ domino_hotfix_version }}"
  when: domino_installer_hotfix_install and not domino_server_hostfix_installed.stat.exists
  ansible.builtin.lineinfile:
    path: "{{ installer_dir }}/domino/hotfix/linux64/script.dat"
    line: "installation_type = 2"

-
  name: "Installing Domino Hotfix {{ domino_hotfix_version }}"
  ansible.builtin.command: "{{ item }}"
  become: true
  become_user: root
  environment:
    NUI_NOTESDIR: "{{ domino_install_basedir }}/"
  args:
    chdir: "{{ installer_dir }}/domino/hotfix/linux64"
    creates: "{{ completed_dir }}/hfinstalled"
    executable: "/bin/bash"
  when: domino_installer_hotfix_install and not domino_server_hostfix_installed.stat.exists
  with_items:
    - "bash ./install -script ./script.dat  && touch {{ completed_dir }}/hfinstalled"
