Added agent2 installation

This commit is contained in:
2025-08-24 15:44:51 +02:00
parent ce3573c708
commit fd46282062

View File

@@ -1,6 +1,6 @@
---
- name: Install and Configure Zabbix Proxy
hosts: zabbix-proxy # Assuming you have a group for zabbix proxy in your inventory
- 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
@@ -14,9 +14,11 @@
ansible.builtin.apt:
deb: /tmp/zabbix-release.deb
- name: Install Zabbix proxy
- name: Install Zabbix proxy and agent
ansible.builtin.apt:
name: zabbix-proxy-sqlite3
name:
- zabbix-proxy-sqlite3
- zabbix-agent2
state: present
update_cache: yes
@@ -40,6 +42,8 @@
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
@@ -55,18 +59,39 @@
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: |
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: |
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 Proxy Service
hosts: zabbix-proxy
- name: Verify Zabbix Services
hosts: zabbix_proxy
become: yes
tasks:
- name: Check if Zabbix proxy service is running
- name: Check if Zabbix services are running
ansible.builtin.service_facts:
- name: Assert that Zabbix proxy is running
@@ -75,3 +100,10 @@
- "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"