ansible/playbooks/00_install_zabbix_agent.yml

156 lines
6.1 KiB
YAML
Raw Normal View History

2023-10-26 13:21:47 +02:00
- hosts: datacenter
2023-10-24 10:19:06 +02:00
name: Install zabbix agent
2024-11-19 14:22:13 +01:00
become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"
2024-06-12 22:18:47 +02:00
vars:
2024-11-19 14:07:21 +01:00
ZABBIX_SERVER: "zabbix.home.lan"
2023-10-24 10:19:06 +02:00
tasks:
2024-06-12 22:18:47 +02:00
2024-11-19 14:22:13 +01:00
- name: Get config for not nas
2024-06-12 22:18:47 +02:00
ansible.builtin.set_fact:
zabbix_agent_cfg: "/etc/zabbix/zabbix_agent2.conf"
2024-11-19 14:22:13 +01:00
when: inventory_hostname != 'nas.home.lan'
2024-06-12 22:18:47 +02:00
2024-11-19 14:22:13 +01:00
- name: Get config for nas
2024-06-12 22:18:47 +02:00
ansible.builtin.set_fact:
zabbix_agent_cfg: "/opt/ZabbixAgent/etc/zabbix_agentd.conf"
2024-11-19 14:22:13 +01:00
when: inventory_hostname == 'nas.home.lan'
2024-06-12 22:18:47 +02:00
- name: Print all available facts
ansible.builtin.debug:
2024-11-19 14:22:13 +01:00
msg: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"
2024-06-12 22:18:47 +02:00
2023-10-26 14:49:56 +02:00
- name: Print all available facts
ansible.builtin.debug:
2023-10-26 15:00:00 +02:00
var: ansible_facts.architecture
2024-11-19 15:26:24 +01:00
- name: Print all available facts
ansible.builtin.debug:
var: ansible_distribution
- name: Print all available facts
ansible.builtin.debug:
var: ansible_distribution_major_version
2023-10-24 12:32:11 +02:00
# - name: Upload zabbix package
# ansible.builtin.copy:
# src: packages/zabbix-release_6.4-1+ubuntu22.04_all.deb
# dest: /tmp/
2024-11-19 15:34:38 +01:00
- name: Install a .deb package from the internet11
2023-10-24 10:19:06 +02:00
ansible.builtin.apt:
2023-10-24 12:32:11 +02:00
deb: https://repo.zabbix.com/zabbix/6.4/ubuntu-arm64/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu22.04_all.deb
2023-10-26 15:02:37 +02:00
when:
2024-11-19 15:36:43 +01:00
- ansible_facts.architecture != "armv7l" and ( ansible_distribution == "Ubuntu" or ansible_distribution == "Linux Mint" )
2024-01-22 00:12:35 +01:00
2024-08-18 23:49:57 +02:00
- name: Install a .deb package from the internet2
2023-10-26 15:02:37 +02:00
ansible.builtin.apt:
2024-06-27 00:19:16 +02:00
#deb: https://repo.zabbix.com/zabbix/6.4/raspbian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb
deb: https://repo.zabbix.com/zabbix/7.0/raspbian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian11_all.deb
2023-10-26 15:10:45 +02:00
retries: 5
delay: 5
2023-10-26 15:02:37 +02:00
when:
2024-08-18 23:49:57 +02:00
- ansible_facts.architecture == "armv7l" or ansible_facts.architecture == "aarch64"
2023-10-26 15:06:22 +02:00
ignore_errors: true
2023-12-12 15:25:23 +01:00
2024-08-18 23:49:57 +02:00
- name: Install a .deb package from the internet3
2023-12-12 15:25:23 +01:00
ansible.builtin.apt:
deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb
2024-06-12 22:18:47 +02:00
2023-12-12 15:25:23 +01:00
when:
2024-01-22 00:12:35 +01:00
- ansible_facts.architecture != "armv7l" and ansible_distribution == "Debian" and ansible_distribution_major_version == "11"
2024-06-12 22:18:47 +02:00
2024-08-18 23:49:57 +02:00
- name: Install a .deb package from the internet4
2024-01-22 00:12:35 +01:00
ansible.builtin.apt:
2024-06-12 22:18:47 +02:00
#deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian12_all.deb
deb: https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian12_all.deb
2024-01-22 00:12:35 +01:00
when:
2024-08-18 23:49:57 +02:00
- ansible_facts.architecture != "armv7l" and ansible_facts.architecture != "aarch64" and ansible_distribution == "Debian" and ansible_distribution_major_version == "12"
2024-01-22 00:12:35 +01:00
2023-10-24 12:32:11 +02:00
# - name: Install a .deb package localy
# ansible.builtin.apt:
# deb: /tmp/zabbix-release_6.4-1+ubuntu22.04_all.deb
2023-10-24 10:19:06 +02:00
- name: Install zabbix packages
ansible.builtin.apt:
name:
- zabbix-agent2
2024-08-18 23:49:57 +02:00
- zabbix-agent2-plugin-mongodb
- zabbix-agent2-plugin-postgresql
2024-11-19 15:33:44 +01:00
- zabbix-agent2-plugin-mysql
2023-10-24 10:19:06 +02:00
update_cache: yes
2024-11-19 15:33:44 +01:00
ignore_errors: true
2024-11-19 14:22:13 +01:00
when: inventory_hostname != 'nas.home.lan'
2024-06-12 22:18:47 +02:00
2023-10-24 10:19:06 +02:00
- name: Reconfigure zabbix agent Server
ansible.builtin.lineinfile:
2024-06-12 22:18:47 +02:00
path: "{{ zabbix_agent_cfg }}"
2023-10-26 13:21:15 +02:00
regexp: "^Server=.*"
2023-10-24 10:19:06 +02:00
insertafter: '^# Server='
2024-06-12 22:18:47 +02:00
line: "Server=192.168.77.0/24"
2024-11-19 14:22:13 +01:00
become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"
2023-10-24 10:19:06 +02:00
- name: Reconfigure zabbix agent ServerActive
ansible.builtin.lineinfile:
2024-06-12 22:18:47 +02:00
path: "{{ zabbix_agent_cfg }}"
2023-10-24 10:19:06 +02:00
regexp: "^ServerActive=.*"
2024-07-25 14:00:42 +02:00
line: "ServerActive={{ ZABBIX_SERVER }}"
2024-06-12 22:18:47 +02:00
2023-10-24 10:19:06 +02:00
- name: Reconfigure zabbix agent ListenPort
ansible.builtin.lineinfile:
2024-06-12 22:18:47 +02:00
path: "{{ zabbix_agent_cfg }}"
2023-10-24 10:19:06 +02:00
regexp: "^ListenPort=.*"
line: "ListenPort=10050"
# - name: Reconfigure zabbix agent ListenIP
# ansible.builtin.lineinfile:
2024-06-12 22:18:47 +02:00
# path: /"{{ zabbix_agent_cfg }}"
2023-10-24 10:19:06 +02:00
# regexp: "^ListenIP=.*"
# line: "ListenIP=0.0.0.0"
2024-11-19 14:22:13 +01:00
2023-10-24 10:19:06 +02:00
- name: Reconfigure zabbix-agent2 hostname
ansible.builtin.lineinfile:
2024-06-12 22:18:47 +02:00
path: "{{ zabbix_agent_cfg }}"
2023-10-24 10:19:06 +02:00
regexp: "^Hostname=.*"
2024-11-19 14:43:05 +01:00
line: "Hostname={{ inventory_hostname }}"
2024-06-12 22:18:47 +02:00
2024-07-25 14:00:42 +02:00
- name: Reconfigure zabbix-agent2 config
ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}"
insertafter: '^# UserParameter='
2024-11-19 14:41:18 +01:00
regexp: "^UserParameter=system.certs.*"
2024-10-22 22:45:14 +02:00
line: "UserParameter=system.certs,python3 /share/ZFS530_DATA/.qpkg/ZabbixAgent/cert_check2.py"
2024-11-19 14:22:13 +01:00
when: inventory_hostname == 'nas.home.lan' or inventory_hostname == 'm-server.home.lan'
2024-10-22 22:31:40 +02:00
2024-10-22 17:59:39 +02:00
- name: Reconfigure zabbix-agent2 config
ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}"
insertafter: '^# UserParameter='
2024-10-22 18:00:03 +02:00
line: "UserParameter=rpi.hw.temp,/usr/bin/vcgencmd measure_temp"
2024-11-19 14:22:13 +01:00
when: inventory_hostname == 'rpi5.home.lan'
2024-07-25 14:00:42 +02:00
2024-06-12 22:18:47 +02:00
- name: Reconfigure zabbix-agent2 hostname
ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}"
regexp: "^HostMetadata=.*"
insertafter: '^# HostMetadata='
line: "HostMetadata=linux;jaydee"
2024-11-19 14:45:36 +01:00
- name: Reconfigure zabbix-agent2 hostname
ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}"
regexp: "^HostMetadata=.*"
insertafter: '^# HostMetadata='
line: "HostMetadata=server;jaydee"
when: inventory_hostname == 'nas.home.lan' or inventory_hostname == 'm-server.home.lan'
2024-06-12 22:18:47 +02:00
2024-11-19 14:22:13 +01:00
- name: Add the user 'to group video
2023-12-05 12:21:17 +01:00
ansible.builtin.user:
name: zabbix
groups: video
append: yes
2024-11-19 14:22:13 +01:00
when: inventory_hostname != 'nas.home.lan'
2024-06-12 22:18:47 +02:00
2023-10-24 10:19:06 +02:00
- name: Restart zabbix-agent2 service
ansible.builtin.service:
name: zabbix-agent2.service
state: restarted
2024-06-12 22:18:47 +02:00
enabled: true
2024-11-19 14:22:13 +01:00
when: inventory_hostname != 'nas.home.lan'
2024-06-12 22:18:47 +02:00
- name: Restart agent
ansible.builtin.shell: /etc/init.d/ZabbixAgent.sh restart
2024-11-19 14:22:13 +01:00
when: inventory_hostname == 'nas.home.lan'