---
# Tasks specific for RedHat systems

- name: "RedHat | Installing zabbix-agent"
  ansible.builtin.package:
    pkg:
      - "{{ zabbix_agent_package }}-{{ zabbix_agent_version }}.{{ zabbix_agent_version_minor }}"
    disablerepo: "{{ zabbix_agent_disable_repo | default(omit) }}"
    state: "{{ zabbix_agent_package_state }}"
  environment:
    http_proxy: "{{ zabbix_http_proxy | default(None) | default(omit) }}"
    https_proxy: "{{ zabbix_https_proxy | default(None) | default(omit) }}"
  register: zabbix_agent_package_installed
  until: zabbix_agent_package_installed is succeeded
  become: true
  tags:
    - install

- name: "RedHat | Installing zabbix-{sender,get}"
  ansible.builtin.package:
    pkg:
      - "{{ zabbix_agent_sender_package }}-{{ zabbix_agent_version }}.{{ zabbix_agent_version_minor }}"
      - "{{ zabbox_agent_get_package }}-{{ zabbix_agent_version }}.{{ zabbix_agent_version_minor }}"
    disablerepo: "{{ zabbix_agent_disable_repo | default(omit) }}"
    state: "{{ zabbix_agent_package_state }}"
  environment:
    http_proxy: "{{ zabbix_http_proxy | default(None) | default(omit) }}"
    https_proxy: "{{ zabbix_https_proxy | default(None) | default(omit) }}"
  register: zabbix_agent_package_installed
  until: zabbix_agent_package_installed is succeeded
  when:
    - not zabbix_agent_install_agent_only
  become: true
  tags:
    - install

- name: "RedHat | Enable the service"
  ansible.builtin.service:
    name: "{{ zabbix_agent_service }}"
    enabled: true
    use: service
  become: true
  tags:
    - service
