Files
ansible/install_zabbix_agent.yml
2024-06-14 08:40:04 +02:00

102 lines
2.7 KiB
YAML

---
# tasks file for zabbix-agent
# Uninstall Zabbix agent
- name: Uninstall Zabbix agent
yum:
name: zabbix-agent
state: absent
# Install Zabbix agent
- name: Install Zabbix agent
yum:
name: zabbix-agent
state: installed
# Delete Zabbix PSK if zabbix_overwrite_psk is true
- name: Delete Zabbix psk
file:
path: /etc/zabbix/zabbix_agentd.psk
state: absent
when: zabbix_overwrite_psk|bool
# Generate Zabbix PSK
- name: Generate Zabbix psk
command: openssl rand -hex -out /etc/zabbix/zabbix_agentd.psk 32
creates: /etc/zabbix/zabbix_agentd.psk
# Change the owner of zabbix_agentd.psk to zabbix
- name: Change the owner of zabbix_agentd.psk to zabbix
file:
path: /etc/zabbix/zabbix_agentd.psk
owner: zabbix
# Register Zabbix agent PSK
- name: Register Zabbix agent psk
command: cat /etc/zabbix/zabbix_agentd.psk
register: zabbix_psk
# Configure Zabbix agent
- name: Configure Zabbix agent
template:
src: zabbix-agent.conf
dest: /etc/zabbix/zabbix_agentd.d/agent.conf
# Ensure that /etc/zabbix/zabbix_agentd.d is included in conf
- name: Ensure that /etc/zabbix/zabbix_agentd.d is included in conf
ini_file:
path: /etc/zabbix_agentd.conf
option: Include
value: /etc/zabbix/zabbix_agentd.d/*.conf
backup: true
# Create a new host or update an existing host's info
- name: Create a new host or update an existing host's info
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: /
ansible_zabbix_auth_key: ad7d2b1e80fa86567d08ac18f4737aabbfd3ab7e91faf205f39a8e7b55b8d7a8
ansible_host: 192.168.1.24
ignore_errors: true
delegate_to: 192.168.1.24
connection: local
zabbix_host:
host_name: "{{ inventory_hostname }}"
visible_name: "{{ inventory_hostname }}"
host_groups:
- "{{ zabbix_host_groups }}"
link_templates:
- "{{ zabbix_link_template }}"
status: enabled
state: present
inventory_mode: automatic
interfaces:
- type: 1
main: 1
useip: 1
ip: "{{ ansible_default_ipv4.address }}"
dns: "{{ inventory_hostname }}"
port: "{{ zabbix_port | default(10050) }}"
tls_connect: 2
tls_accept: 2
tls_psk_identity: "PSK-{{ inventory_hostname }}"
tls_psk: "{{ zabbix_psk.stdout }}"
proxy: "{{ zabbix_proxy | default(omit) }}"
become: false
# Enable Zabbix on Reboot
- name: Enable Zabbix on Reboot
service:
name: zabbix-agent
enabled: true
# Restart Zabbix
- name: Restart Zabbix
service:
name: zabbix-agent
state: restarted