| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- ---
- - name: "Upgrade to Zabbix Agent2 for Zabbix 7 for supported distros and versions using dnf/yum/apt"
- hosts: all
- gather_facts: True
- become: true
- # Put the most recent version of the Zabbix release here:
- vars:
- ZABBIXRELEASEVERSION: "7.2"
- tasks:
- - name: "msg print to stdout: Debug ansible_facts"
- debug:
- msg:
- # - "{{ ansible_facts.service_mgr }}"
- - ansible_facts.distribution "{{ ansible_facts.distribution }}"
- - ansible_facts.distribution_major_version "{{ ansible_facts.distribution_major_version }}"
- - ansible_facts.distribution_file_variety "{{ ansible_facts.distribution_file_variety }}"
- - name: "Try to register variables used later"
- set_fact:
- raw_major_version: "{{ ansible_facts.distribution_major_version }}"
- lowercase_distro_name: "{{ ansible_facts.distribution|lower }}"
- - name: "Display the above variables"
- debug:
- msg:
- - "raw_major_version is {{ raw_major_version }}"
- - "lowercase_distro_name is {{ lowercase_distro_name }}"
- - "ZABBIXRELEASEVERSION is {{ ZABBIXRELEASEVERSION }}"
- - name: Populate systemd service_facts
- service_facts:
- ####################################### For RH-like distros #########################################
- - name: Remove old /etc/yum.repos.d/zabbix.repo file if it exists; RH-like, v8+
- file:
- path: /etc/yum.repos.d/zabbix.repo
- state: absent
- when: (ansible_facts['distribution_file_variety'] == 'RedHat') and (ansible_facts['distribution_major_version'] >= '8')
- - name: Create zabbix-release.repo file; RH-like, v8+
- yum_repository:
- name: zabbix-release
- description: "Zabbix 7 Official Repository (release packages) - noarch"
- file: zabbix-repo
- baseurl: "https://repo.zabbix.com/zabbix/{{ ZABBIXRELEASEVERSION }}/release/{{ lowercase_distro_name }}/{{ raw_major_version }}/noarch/"
- gpgcheck: yes
- gpgkey: https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-B5333005
- enabled: yes
- when: (ansible_facts['distribution_file_variety'] == 'RedHat') and (ansible_facts['distribution_major_version'] >= '8')
- - name: Add latest Zabbix GPG keys for RH-like distros
- rpm_key:
- state: present
- key: https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-08EFA7DD
- when: ansible_facts['distribution_file_variety'] == 'RedHat'
- - name: Install zabbix-release
- package:
- name: zabbix-release
- state: present
- - name: Install zabbix-agent2
- package:
- name: zabbix-agent2
- state: present
- ########################################## Copy zabbix-agent2.conf file ########################################
- - name: Copy zabbix_agent2.conf file to host
- copy:
- src: include/zabbix7/zabbix_agent2.conf
- dest: /etc/zabbix/zabbix_agent2.conf
- owner: zabbix
- group: zabbix
- mode: '0640'
- ########################################## Remove old/unused files ########################################
- - name: Remove old/unused .conf files
- file:
- path: /zabbix/zabbix_agentd.conf
- state: absent
- - name: Remove old/unused log files
- file:
- path: /var/log/zabbix/zabbix_agentd.log
- state: absent
- - name: Remove old/unused gzipped log files
- file:
- path: /var/log/zabbix/zabbix_agentd.log-*.gz
- state: absent
- - name: Remove old Zabbix GPG keys for RH-like distros
- rpm_key:
- state: absent
- key:
- - 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-79EA5ED4'
- - 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-A14FE591'
- - 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-A14FE591-EL5'
- when: ansible_facts['distribution_file_variety'] == 'RedHat'
- ignore_errors: true
- ########################################## Correct permissions ########################################
- - name: Fix permissions for /var/log/zabbix
- file:
- path: /var/log/zabbix
- state: directory
- recurse: yes
- owner: zabbix
- group: zabbix
- - name: Fix permissions for /etc/zabbix
- file:
- path: /etc/zabbix
- state: directory
- recurse: yes
- owner: zabbix
- group: zabbix
- ########################################## Start and enable zabbix-agent2.service ########################################
- - name: 'Start and enable zabbix-agent2.service'
- systemd:
- name: zabbix-agent2
- state: restart
- daemon_reload: true
- enabled: true
- when: ansible_facts.service_mgr == "systemd"
- ############################################### Debian & Ubuntu section #################################################################################################
- # 01-07-2025: Updated repo URLs
- - name: Install zabbix-release for appropriate version of Debian
- apt:
- deb: "https://repo.zabbix.com/zabbix/{{ ZABBIXRELEASEVERSION }}/release/{{ lowercase_distro_name }}/pool/main/z/zabbix-release/zabbix-release_latest_{{ ZABBIXRELEASEVERSION }}+{{ lowercase_distro_name }}{{ raw_major_version }}_all.deb"
- state: present
- when:
- - ansible_facts['distribution'] == 'Debian'
- - ansible_facts['distribution_major_version'] >= '10'
- - name: Install zabbix-release for appropriate version of Ubuntu
- apt:
- deb: "https://repo.zabbix.com/zabbix/{{ ZABBIXRELEASEVERSION }}/release/{{ lowercase_distro_name }}/pool/main/z/zabbix-release/zabbix-release_latest_{{ ZABBIXRELEASEVERSION }}+{{ lowercase_distro_name }}{{ raw_major_version }}_all.deb"
- state: present
- when:
- - ansible_facts['distribution'] == 'Ubuntu'
- - ansible_facts['distribution_major_version'] >= '16.04'
|