---
# Tasks specific for Debian/Ubuntu Systems

- name: "Debian | Installing zabbix-agent"
  ansible.builtin.apt:
    pkg: "{{ zabbix_agent_package }}"
    state: "{{ zabbix_agent_package_state }}"
    update_cache: true
    cache_valid_time: 0
    force_apt_get: "{{ zabbix_apt_force_apt_get }}"
    install_recommends: "{{ zabbix_apt_install_recommends }}"
  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: "Debian | Installing zabbix-{sender,get}"
  ansible.builtin.apt:
    pkg:
      - "{{ zabbix_agent_sender_package }}"
      - "{{ zabbox_agent_get_package }}"
    state: "{{ zabbix_agent_package_state }}"
    update_cache: true
    cache_valid_time: 0
    force_apt_get: "{{ zabbix_apt_force_apt_get }}"
    install_recommends: "{{ zabbix_apt_install_recommends }}"
  environment:
    http_proxy: "{{ zabbix_http_proxy | default(None) | default(omit) }}"
    https_proxy: "{{ zabbix_https_proxy | default(None) | default(omit) }}"
  when:
    - not zabbix_agent_install_agent_only
  register: zabbix_agent_package_installed
  until: zabbix_agent_package_installed is succeeded
  become: true
  check_mode: false
  tags:
    - install

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