--- - name: Install and Configure Zabbix Proxy and Agent hosts: zabbix-proxy # Assuming you have a group for zabbix proxy in your inventory become: yes vars_files: - ../secrets.yml tasks: - name: Download Zabbix release package ansible.builtin.get_url: url: "https://repo.zabbix.com/zabbix/7.4/release/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.4+ubuntu24.04_all.deb" dest: /tmp/zabbix-release.deb - name: Install Zabbix release package ansible.builtin.apt: deb: /tmp/zabbix-release.deb - name: Install Zabbix proxy and agent ansible.builtin.apt: name: - zabbix-proxy-sqlite3 - zabbix-agent2 state: present update_cache: yes - name: Create Zabbix proxy custom configuration file ansible.builtin.copy: dest: /etc/zabbix/zabbix_proxy.d/custom.conf content: | ## Managed by Ansible - do not edit manually ## ## Changes will be overwritten ## DBName=/tmp/zabbix_proxy StartPollers=2 StartPreprocessors=1 StartTrappers=1 StartDiscoverers=1 StartDBSyncers=1 StartAgentPollers=2 EnableRemoteCommands=1 TLSConnect=psk TLSAccept=psk notify: restart zabbix-proxy - name: Create Zabbix proxy connection configuration file ansible.builtin.copy: dest: /etc/zabbix/zabbix_proxy.d/connection.conf content: | ## Managed by Ansible - do not edit manually ## ## Changes will be overwritten ## Server={{ zabbix_server_address }}:10051 Hostname={{ ansible_facts.hostname }} TLSPSKFile=/etc/zabbix/{{ ansible_facts.hostname }}.psk TLSPSKIdentity={{ zabbix_psk_identity }} notify: restart zabbix-proxy - name: Create Zabbix proxy PSK file ansible.builtin.copy: dest: "/etc/zabbix/{{ ansible_facts.hostname }}.psk" content: "{{ zabbix_proxy_psk }}" owner: zabbix group: zabbix mode: '0600' notify: restart zabbix-proxy - name: Create Zabbix agent custom configuration file ansible.builtin.copy: dest: /etc/zabbix/zabbix_agent2.d/custom.conf content: | ## Managed by Ansible - do not edit manually ## ## Changes will be overwritten ## Hostname={{ ansible_facts.hostname }} Server={{ hostvars['zabbix-proxy']['ansible_host'] }},{{ hostvars['raspberry-pi']['ansible_host'] }} ServerActive={{ hostvars['zabbix-proxy']['ansible_host'] }};{{ hostvars['raspberry-pi']['ansible_host'] }} notify: restart zabbix-agent2 - name: Create Zabbix agent user parameters file ansible.builtin.copy: dest: /etc/zabbix/zabbix_agent2.d/userparams.conf content: | ## Managed by Ansible - do not edit manually ## ## Changes will be overwritten ## AllowKey=system.run[*] notify: restart zabbix-agent2 handlers: - name: restart zabbix-proxy ansible.builtin.service: name: zabbix-proxy state: restarted enabled: yes - name: restart zabbix-agent2 ansible.builtin.service: name: zabbix-agent2 state: restarted enabled: yes - name: Verify Zabbix Services hosts: zabbix-proxy become: yes tasks: - name: Check if Zabbix services are running ansible.builtin.service_facts: - name: Assert that Zabbix proxy is running ansible.builtin.assert: that: - "ansible_facts.services['zabbix-proxy.service'].state == 'running'" fail_msg: "Zabbix proxy is not running" success_msg: "Zabbix proxy is running" - name: Assert that Zabbix agent is running ansible.builtin.assert: that: - "ansible_facts.services['zabbix-agent2.service'].state == 'running'" fail_msg: "Zabbix agent 2 is not running" success_msg: "Zabbix agent 2 is running"