--- - name: Ensure Zabbix agent network configuration is correct hosts: all become: true tasks: - name: Open firewall port 10050 for Zabbix agent (Debian) when: ansible_os_family == "Debian" community.general.ufw: rule: allow port: 10050 proto: tcp - name: Open firewall port 10050 for Zabbix agent (RedHat) when: ansible_os_family == "RedHat" ansible.posix.firewalld: service: zabbix-agent port: 10050/tcp permanent: true state: enabled immediate: true - name: Restart firewall to apply changes (Debian) ansible.builtin.service: name: ufw state: restarted when: ansible_os_family == "Debian" - name: Restart firewalld to apply changes (RedHat) ansible.builtin.service: name: firewalld state: restarted when: ansible_os_family == "RedHat" - name: Create directory for Zabbix agent configuration if it does not exist ansible.builtin.file: path: /etc/zabbix/zabbix_agentd.d state: directory - name: Create directory for Zabbix agent logs if it does not exist ansible.builtin.file: path: /var/log/zabbix state: directory - name: Ensure /var/log/zabbix directory is owned by zabbix user ansible.builtin.file: path: /var/log/zabbix owner: zabbix group: zabbix state: directory - name: Ensure Zabbix agent is running ansible.builtin.service: name: zabbix-agent state: restarted - name: Check Zabbix agent status ansible.builtin.command: systemctl status zabbix-agent register: zabbix_status - name: Debug Zabbix agent status ansible.builtin.debug: msg: "{{ zabbix_status.stdout_lines }}"