This commit is contained in:
2025-04-26 19:37:01 +02:00
parent 5ab8d6cf02
commit f339cb755a

View File

@ -1,175 +1,172 @@
- block: - name: Install zabbix agent
- name: Get config for not nas become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"
ansible.builtin.set_fact: block:
zabbix_agent_cfg: "/etc/zabbix/zabbix_agent2.conf" - name: Get config for not nas
when: inventory_hostname != 'nas.home.lan' ansible.builtin.set_fact:
zabbix_agent_cfg: "/etc/zabbix/zabbix_agent2.conf"
- name: Get config for nas when: inventory_hostname != 'nas.home.lan'
ansible.builtin.set_fact:
zabbix_agent_cfg: "/opt/ZabbixAgent/etc/zabbix_agentd.conf"
when: inventory_hostname == 'nas.home.lan'
- name: Print all available facts - name: Get config for nas
ansible.builtin.debug: ansible.builtin.set_fact:
msg: "{{ false if inventory_hostname == 'nas.home.lan' else true }}" zabbix_agent_cfg: "/opt/ZabbixAgent/etc/zabbix_agentd.conf"
when: inventory_hostname == 'nas.home.lan'
- name: Print all available facts - name: Print all available facts
ansible.builtin.debug: ansible.builtin.debug:
var: ansible_facts.architecture msg: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"
- name: Print all available facts
ansible.builtin.debug:
var: ansible_distribution
- name: Print all available facts
ansible.builtin.debug:
var: ansible_distribution_major_version
# - name: Upload zabbix package
# ansible.builtin.copy:
# src: packages/zabbix-release_6.4-1+ubuntu22.04_all.deb
# dest: /tmp/
- name: Install a .deb package from the internet111
ansible.builtin.apt:
deb: https://repo.zabbix.com/zabbix/7.2/release/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.2+ubuntu24.04_all.deb
when:
- ansible_facts.architecture != "armv7l" and ( ansible_distribution == "Ubuntu1" or ansible_distribution == "Linux Mint" )
- name: Install a .deb package from the internet2 - name: Print all available facts
ansible.builtin.apt: ansible.builtin.debug:
#deb: https://repo.zabbix.com/zabbix/6.4/raspbian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb var: ansible_facts.architecture
deb: https://repo.zabbix.com/zabbix/7.0/raspbian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian11_all.deb - name: Print all available facts
retries: 5 ansible.builtin.debug:
delay: 5 var: ansible_distribution
when: - name: Print all available facts
- ansible_facts.architecture == "armv7l" or ansible_facts.architecture == "aarch64" ansible.builtin.debug:
var: ansible_distribution_major_version
# - name: Upload zabbix package
# ansible.builtin.copy:
# src: packages/zabbix-release_6.4-1+ubuntu22.04_all.deb
# dest: /tmp/
- name: Install a .deb package from the internet111
ansible.builtin.apt:
deb: https://repo.zabbix.com/zabbix/7.2/release/ubuntu/pool/main/z/zabbix-release/zabbix-release_latest_7.2+ubuntu24.04_all.deb
when:
- ansible_facts.architecture != "armv7l" and ( ansible_distribution == "Ubuntu1" or ansible_distribution == "Linux Mint" )
ignore_errors: true - name: Install a .deb package from the internet2
ansible.builtin.apt:
# 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
retries: 5
delay: 5
when:
- ansible_facts.architecture == "armv7l" or ansible_facts.architecture == "aarch64"
register: command_result
failed_when: "'FAILED' in command_result.stderr"
- name: Install a .deb package from the internet3 - name: Install a .deb package from the internet3
ansible.builtin.apt: 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 deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian11_all.deb
when:
when: - ansible_facts.architecture != "armv7l" and ansible_distribution == "Debian" and ansible_distribution_major_version == "11"
- ansible_facts.architecture != "armv7l" and ansible_distribution == "Debian" and ansible_distribution_major_version == "11"
- name: Install a .deb package from the internet4
ansible.builtin.apt:
#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
when:
- ansible_facts.architecture != "armv7l" and ansible_facts.architecture != "aarch64" and ansible_distribution == "Debian" and ansible_distribution_major_version == "12"
ignore_errors: true
# - name: Install a .deb package localy - name: Install a .deb package from the internet4
# ansible.builtin.apt: ansible.builtin.apt:
# deb: /tmp/zabbix-release_6.4-1+ubuntu22.04_all.deb # deb: https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian12_all.deb
- name: Install zabbix packages deb: https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_7.0-1+debian12_all.deb
ansible.builtin.apt: when:
name: - ansible_facts.architecture != "armv7l"
- zabbix-agent2 - ansible_facts.architecture != "aarch64"
- zabbix-agent2-plugin-mongodb - ansible_distribution == "Debian"
- zabbix-agent2-plugin-postgresql - ansible_distribution_major_version == "12"
# - zabbix-agent2-plugin-mysql register: command_result
update_cache: yes failed_when: "'FAILED' in command_result.stderr"
ignore_errors: true # - name: Install a .deb package localy
when: inventory_hostname != 'nas.home.lan' # ansible.builtin.apt:
# deb: /tmp/zabbix-release_6.4-1+ubuntu22.04_all.deb
- name: Install zabbix packages
ansible.builtin.apt:
name:
- zabbix-agent2
- zabbix-agent2-plugin-mongodb
- zabbix-agent2-plugin-postgresql
# - zabbix-agent2-plugin-mysql
update_cache: true
when: inventory_hostname != 'nas.home.lan'
- name: Reconfigure zabbix agent Server - name: Reconfigure zabbix agent Server
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
regexp: "^Server=.*" regexp: "^Server=.*"
insertafter: '^# Server=' insertafter: '^# Server='
line: "Server=192.168.77.0/24,192.168.89.0/28" line: "Server=192.168.77.0/24,192.168.89.0/28"
- name: Reconfigure zabbix agent ServerActive - name: Reconfigure zabbix agent ServerActive
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
regexp: "^ServerActive=.*" regexp: "^ServerActive=.*"
line: "ServerActive={{ ZABBIX_SERVER }}" line: "ServerActive={{ ZABBIX_SERVER }}"
- name: Reconfigure zabbix agent ListenPort - name: Reconfigure zabbix agent ListenPort
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
regexp: "^ListenPort=.*" regexp: "^ListenPort=.*"
line: "ListenPort=10050" line: "ListenPort=10050"
# - name: Reconfigure zabbix agent ListenIP # - name: Reconfigure zabbix agent ListenIP
# ansible.builtin.lineinfile: # ansible.builtin.lineinfile:
# path: /"{{ zabbix_agent_cfg }}" # path: /"{{ zabbix_agent_cfg }}"
# regexp: "^ListenIP=.*" # regexp: "^ListenIP=.*"
# line: "ListenIP=0.0.0.0" # line: "ListenIP=0.0.0.0"
- name: Reconfigure zabbix-agent2 hostname - name: Reconfigure zabbix-agent2 hostname
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
regexp: "^Hostname=.*" regexp: "^Hostname=.*"
line: "Hostname={{ inventory_hostname }}" line: "Hostname={{ inventory_hostname }}"
- name: Reconfigure zabbix-agent2 config - name: Reconfigure zabbix-agent2 config
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
insertafter: '^# UserParameter=' insertafter: '^# UserParameter='
regexp: "^UserParameter=system.certs.*" regexp: "^UserParameter=system.certs.*"
line: "UserParameter=system.certs,python3 /share/ZFS530_DATA/.qpkg/ZabbixAgent/cert_check2.py" line: "UserParameter=system.certs,python3 /share/ZFS530_DATA/.qpkg/ZabbixAgent/cert_check2.py"
when: inventory_hostname == 'nas.home.lan' when: inventory_hostname == 'nas.home.lan'
- name: Reconfigure zabbix-agent2 config - name: Reconfigure zabbix-agent2 config
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
insertafter: '^# UserParameter=' insertafter: '^# UserParameter='
regexp: "^UserParameter=system.certs.*" regexp: "^UserParameter=system.certs.*"
line: "UserParameter=system.certs,python3 /usr/bin/cert_check2.py" line: "UserParameter=system.certs,python3 /usr/bin/cert_check2.py"
when: inventory_hostname == 'm-server.home.lan' when: inventory_hostname == 'm-server.home.lan'
- name: Reconfigure zabbix-agent2 config - name: Reconfigure zabbix-agent2 config
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
insertafter: '^# UserParameter=' insertafter: '^# UserParameter='
line: "UserParameter=rpi.hw.temp,/usr/bin/vcgencmd measure_temp" line: "UserParameter=rpi.hw.temp,/usr/bin/vcgencmd measure_temp"
when: inventory_hostname == 'rpi5.home.lan' when: inventory_hostname == 'rpi5.home.lan'
- name: Reconfigure zabbix-agent2 hostname - name: Reconfigure zabbix-agent2 hostname
ansible.builtin.lineinfile: ansible.builtin.lineinfile:
path: "{{ zabbix_agent_cfg }}" path: "{{ zabbix_agent_cfg }}"
regexp: "^HostMetadata=.*" regexp: "^HostMetadata=.*"
insertafter: '^# HostMetadata=' insertafter: '^# HostMetadata='
line: "HostMetadata=linux;jaydee" line: "HostMetadata=linux;jaydee"
- 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'
- name: Add the user 'to group video
ansible.builtin.user:
name: zabbix
groups: video
append: true
when: inventory_hostname != 'nas.home.lan'
- name: Restart zabbix-agent2 service
- name: Reconfigure zabbix-agent2 hostname ansible.builtin.service:
ansible.builtin.lineinfile: name: zabbix-agent2.service
path: "{{ zabbix_agent_cfg }}" state: restarted
regexp: "^HostMetadata=.*" enabled: true
insertafter: '^# HostMetadata=' when: inventory_hostname != 'nas.home.lan'
line: "HostMetadata=server;jaydee"
when: inventory_hostname == 'nas.home.lan' or inventory_hostname == 'm-server.home.lan'
- name: Restart agent
- name: Add the user 'to group video ansible.builtin.command: /etc/init.d/ZabbixAgent.sh restart
ansible.builtin.user: when: inventory_hostname == 'nas.home.lan'
name: zabbix changed_when: false
groups: video
append: yes
when: inventory_hostname != 'nas.home.lan'
- name: Restart zabbix-agent2 service
ansible.builtin.service:
name: zabbix-agent2.service
state: restarted
enabled: true
when: inventory_hostname != 'nas.home.lan'
- name: Restart agent
ansible.builtin.shell: /etc/init.d/ZabbixAgent.sh restart
when: inventory_hostname == 'nas.home.lan'
become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"