zabbix-agent2

This commit is contained in:
2025-12-11 22:13:52 +01:00
commit 4fc40bb123

View File

@@ -0,0 +1,93 @@
---
- name: Install and Configure Zabbix Agent 2
hosts: all
become: true
vars:
# DEFINABLE VARIABLES
zabbix_server_ip: "10.10.10.10" # REPLACE THIS or pass via -e
zabbix_hostname: "{{ inventory_hostname }}"
zabbix_version_major: "7.0"
# Internal variables for repo URLs
zabbix_rhel_repo_url: "https://repo.zabbix.com/zabbix/{{ zabbix_version_major }}/rhel/{{ ansible_distribution_major_version }}/x86_64/zabbix-release-latest.el{{ ansible_distribution_major_version }}.noarch.rpm"
# Note: Debian repo often versions the release package (e.g., 7.0-2). Adjust if 404.
zabbix_deb_repo_url: "https://repo.zabbix.com/zabbix/{{ zabbix_version_major }}/debian/pool/main/z/zabbix-release/zabbix-release_{{ zabbix_version_major }}-2+debian{{ ansible_distribution_major_version }}_all.deb"
zabbix_ubuntu_repo_url: "https://repo.zabbix.com/zabbix/{{ zabbix_version_major }}/ubuntu/pool/main/z/zabbix-release/zabbix-release_{{ zabbix_version_major }}-2+ubuntu{{ ansible_distribution_version }}_all.deb"
tasks:
# ---------------------------------------------------------
# 1. Repository Setup
# ---------------------------------------------------------
- name: "RHEL/Alma | Install Zabbix Release RPM"
ansible.builtin.dnf:
name: "{{ zabbix_rhel_repo_url }}"
state: present
disable_gpg_check: true
when: ansible_os_family == "RedHat"
- name: "Debian | Download Zabbix Release DEB"
ansible.builtin.get_url:
url: "{{ zabbix_deb_repo_url }}"
dest: "/tmp/zabbix-release.deb"
when: ansible_distribution == "Debian"
- name: "Ubuntu | Download Zabbix Release DEB"
ansible.builtin.get_url:
url: "{{ zabbix_ubuntu_repo_url }}"
dest: "/tmp/zabbix-release.deb"
when: ansible_distribution == "Ubuntu"
- name: "Debian/Ubuntu | Install Zabbix Release DEB"
ansible.builtin.apt:
deb: "/tmp/zabbix-release.deb"
update_cache: true
when: ansible_os_family == "Debian"
# ---------------------------------------------------------
# 2. Package Installation
# ---------------------------------------------------------
- name: Install Zabbix Agent 2 and Plugins
ansible.builtin.package:
name:
- zabbix-agent2
- zabbix-agent2-plugin-*
state: present
# ---------------------------------------------------------
# 3. Configuration
# ---------------------------------------------------------
- name: Configure Zabbix Server IP (Passive)
ansible.builtin.lineinfile:
path: /etc/zabbix/zabbix_agent2.conf
regexp: '^Server='
line: "Server={{ zabbix_server_ip }}"
notify: Restart Zabbix Agent2
- name: Configure Zabbix ServerActive IP (Active)
ansible.builtin.lineinfile:
path: /etc/zabbix/zabbix_agent2.conf
regexp: '^ServerActive='
line: "ServerActive={{ zabbix_server_ip }}"
notify: Restart Zabbix Agent2
- name: Configure Hostname
ansible.builtin.lineinfile:
path: /etc/zabbix/zabbix_agent2.conf
regexp: '^Hostname='
line: "Hostname={{ zabbix_hostname }}"
notify: Restart Zabbix Agent2
# ---------------------------------------------------------
# 4. Service Management
# ---------------------------------------------------------
- name: Ensure Zabbix Agent 2 is started and enabled
ansible.builtin.service:
name: zabbix-agent2
state: started
enabled: true
handlers:
- name: Restart Zabbix Agent2
ansible.builtin.service:
name: zabbix-agent2
state: restarted