---
- name: (yum.yml) Install system updates for redhat (centos/fedora) systems
  ansible.builtin.dnf:
    name: "*"
    state: latest
    update_cache: true
    #cache_valid_time: 3600
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS" or ansible_facts.distribution == "Fedora"
  tags:
    - yum-update

- name: Install the EPEL Repository in CentOS 7
  ansible.builtin.dnf:
    name: epel-release
    state: latest
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS"

# Its more eficient to in
- name: (yum.yml) Base install CentOS packages (CentOS 7)
  ansible.builtin.dnf:
    name: "{{ yum_base_install_centos_7 }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS"
    - ansible_facts.distribution_major_version == "7"
  tags:
    - yum-base-install

- name: (yum.yml) Initial install CentOS packages (CentOS 7)
  ansible.builtin.dnf:
    name: "{{ yum_initial_install_centos_7 }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS"
    - ansible_facts.distribution_major_version == "7"
  tags:
    - yum-initial-install

# Its more eficient to in
- name: (yum.yml) Base install Fedira packages (Fedora 38)
  ansible.builtin.dnf:
    name: "{{ yum_base_install_fedora_38 }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "Fedora"
    - ansible_facts.distribution_major_version == "38"
  tags:
    - yum-base-install

- name: (yum.yml) Initial install Fedora packages (Fedora 38)
  ansible.builtin.dnf:
    name: "{{ yum_initial_install_fedora_38 }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "Fedora"
    - ansible_facts.distribution_major_version == "38"
  tags:
    - yum-initial-install

- name: (yum.yml) Install lxc_host related packages CentOS systems
  ansible.builtin.dnf:
    name: "{{ yum_lxc_host_pkgs_centos }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS"
    - groups['lxc_host']|string is search(inventory_hostname)
  tags:
    - yum-lxc-hosts-pkgs

- name: (yum.yml) Install lxc_host related packages Fedora systems
  ansible.builtin.dnf:
    name: "{{ yum_lxc_host_pkgs_fedora }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "Fedora"
    - groups['lxc_host']|string is search(inventory_hostname)
  tags:
    - yum-lxc-hosts-pkgs

- name: (yum.yml) Install postgresql server related packages CentOS systems
  ansible.builtin.dnf:
    name: "{{ yum_postgresql_pkgs_centos }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS"
    - install_postgresql_pkgs|bool
  tags:
    - apt-postgresql-server-pkgs

- name: (yum.yml) Install postgresql server related packages Fedora systems
  ansible.builtin.dnf:
    name: "{{ yum_postgresql_pkgs_fedora }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "Fedora"
    - install_postgresql_pkgs|bool
  tags:
    - apt-postgresql-server-pkgs

- name: (yum.yml) Install compile related packages CentOS systems
  ansible.builtin.dnf:
    name: "{{ yum_compiler_pkgs_centos }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS"
    - install_compiler_pkgs|bool
  tags:
    - yum-compiler-pkgs

- name: (yum.yml) Install compile related packages Fedora systems
  ansible.builtin.dnf:
    name: "{{ yum_compiler_pkgs_fedora }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "Fedora"
    - install_compiler_pkgs|bool
  tags:
    - yum-compiler-pkgs

- name: (yum.yml) Install webserver related packages CentOS systems
  ansible.builtin.dnf:
    name: "{{ yum_webserver_pkgs_centos }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "CentOS"
    - install_webserver_pkgs|bool
  tags:
    - yum-webserver-pkgs

- name: (yum.yml) Install webserver related packages Fedora systems
  ansible.builtin.dnf:
    name: "{{ yum_webserver_pkgs_fedora }}"
    state: "{{ yum_install_state }}"
  when:
    - ansible_facts.os_family == "RedHat"
    - ansible_facts.distribution == "Fedora"
    - install_webserver_pkgs|bool
  tags:
    - yum-webserver-pkgs
