ansible/playbooks/00_install_zabbix_agent.yml

165 lines
6.9 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-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
- name: Combine list1 and list2 into a merged_list var
ansible.builtin.set_fact:
zabbix_agent_cfg: "/etc/zabbix/zabbix_agent2.conf"
2024-11-19 14:07:21 +01:00
when: inventory_hostname not in groups['nas.home.lan']
2024-06-12 22:18:47 +02:00
- name: Combine list1 and list2 into a merged_list var
ansible.builtin.set_fact:
zabbix_agent_cfg: "/opt/ZabbixAgent/etc/zabbix_agentd.conf"
2024-11-19 14:07:21 +01:00
when: inventory_hostname in groups['nas.home.lan']
2024-06-12 22:18:47 +02:00
- name: Print all available facts
ansible.builtin.debug:
2024-11-19 14:07:21 +01:00
msg: "{{ false if inventory_hostname not in groups['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
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-08-18 23:49:57 +02:00
- name: Install a .deb package from the internet1
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:
2023-12-12 15:25:23 +01:00
- ansible_facts.architecture != "armv7l" and ansible_distribution == "Ubuntu"
2024-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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
2024-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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
- zabbix-agent2-plugin-mssql
2023-10-24 10:19:06 +02:00
update_cache: yes
2024-11-19 14:07:21 +01:00
when: inventory_hostname not in groups['nas.home.lan']
become: "{{ false if inventory_hostname in groups['nas.home.lan'] else true }}"
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:07:21 +01:00
become: "{{ false if inventory_hostname in groups['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-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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=.*"
line: "Hostname={{ansible_hostname}}"
2024-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
2024-06-12 22:18:47 +02:00
2023-12-05 12:21:17 +01:00
- name: Reconfigure zabbix-agent2 hostname
ansible.builtin.lineinfile:
2024-06-12 22:18:47 +02:00
path: "{{ zabbix_agent_cfg }}"
2023-12-05 12:21:17 +01:00
insertafter: '^# UserParameter='
line: "UserParameter=system.temperature,vcgencmd measure_temp"
2024-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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-10-22 22:45:14 +02:00
line: "UserParameter=system.certs,python3 /share/ZFS530_DATA/.qpkg/ZabbixAgent/cert_check2.py"
2024-11-19 14:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
when: inventory_hostname in groups['nas.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:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
when: inventory_hostname in groups['rpi5.home.lan']
2024-10-22 17:59:39 +02:00
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:07:21 +01:00
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
2024-06-12 22:18:47 +02:00
2023-12-05 12:21:17 +01:00
- name: Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
ansible.builtin.user:
name: zabbix
groups: video
append: yes
2024-11-19 14:07:21 +01:00
when: inventory_hostname not in groups['nas.home.lan']
become: "{{ 'no' if inventory_hostname in groups['nas.home.lan'] else 'yes' }}"
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
become: true
2024-11-19 14:07:21 +01:00
when: inventory_hostname not in groups['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:07:21 +01:00
when: inventory_hostname in groups['nas.home.lan']