upgrade_zabbix-agent7.playbook.yaml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ---
  2. - name: "Upgrade to Zabbix Agent2 for Zabbix 7 for supported distros and versions using dnf/yum/apt"
  3. hosts: all
  4. gather_facts: True
  5. become: true
  6. # Put the most recent version of the Zabbix release here:
  7. vars:
  8. ZABBIXRELEASEVERSION: "7.2"
  9. tasks:
  10. - name: "msg print to stdout: Debug ansible_facts"
  11. debug:
  12. msg:
  13. # - "{{ ansible_facts.service_mgr }}"
  14. - ansible_facts.distribution "{{ ansible_facts.distribution }}"
  15. - ansible_facts.distribution_major_version "{{ ansible_facts.distribution_major_version }}"
  16. - ansible_facts.distribution_file_variety "{{ ansible_facts.distribution_file_variety }}"
  17. - name: "Try to register variables used later"
  18. set_fact:
  19. raw_major_version: "{{ ansible_facts.distribution_major_version }}"
  20. lowercase_distro_name: "{{ ansible_facts.distribution|lower }}"
  21. - name: "Display the above variables"
  22. debug:
  23. msg:
  24. - "raw_major_version is {{ raw_major_version }}"
  25. - "lowercase_distro_name is {{ lowercase_distro_name }}"
  26. - "ZABBIXRELEASEVERSION is {{ ZABBIXRELEASEVERSION }}"
  27. - name: Populate systemd service_facts
  28. service_facts:
  29. ####################################### For RH-like distros #########################################
  30. - name: Remove old /etc/yum.repos.d/zabbix.repo file if it exists; RH-like, v8+
  31. file:
  32. path: /etc/yum.repos.d/zabbix.repo
  33. state: absent
  34. when: (ansible_facts['distribution_file_variety'] == 'RedHat') and (ansible_facts['distribution_major_version'] >= '8')
  35. - name: Create zabbix-release.repo file; RH-like, v8+
  36. yum_repository:
  37. name: zabbix-release
  38. description: "Zabbix 7 Official Repository (release packages) - noarch"
  39. file: zabbix-repo
  40. baseurl: "https://repo.zabbix.com/zabbix/{{ ZABBIXRELEASEVERSION }}/release/{{ lowercase_distro_name }}/{{ raw_major_version }}/noarch/"
  41. gpgcheck: yes
  42. gpgkey: https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-B5333005
  43. enabled: yes
  44. when: (ansible_facts['distribution_file_variety'] == 'RedHat') and (ansible_facts['distribution_major_version'] >= '8')
  45. - name: Add latest Zabbix GPG keys for RH-like distros
  46. rpm_key:
  47. state: present
  48. key: https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-08EFA7DD
  49. when: ansible_facts['distribution_file_variety'] == 'RedHat'
  50. - name: Install zabbix-release
  51. package:
  52. name: zabbix-release
  53. state: present
  54. - name: Install zabbix-agent2
  55. package:
  56. name: zabbix-agent2
  57. state: present
  58. ########################################## Copy zabbix-agent2.conf file ########################################
  59. - name: Copy zabbix_agent2.conf file to host
  60. copy:
  61. src: include/zabbix7/zabbix_agent2.conf
  62. dest: /etc/zabbix/zabbix_agent2.conf
  63. owner: zabbix
  64. group: zabbix
  65. mode: '0640'
  66. ########################################## Remove old/unused files ########################################
  67. - name: Remove old/unused .conf files
  68. file:
  69. path: /zabbix/zabbix_agentd.conf
  70. state: absent
  71. - name: Remove old/unused log files
  72. file:
  73. path: /var/log/zabbix/zabbix_agentd.log
  74. state: absent
  75. - name: Remove old/unused gzipped log files
  76. file:
  77. path: /var/log/zabbix/zabbix_agentd.log-*.gz
  78. state: absent
  79. - name: Remove old Zabbix GPG keys for RH-like distros
  80. rpm_key:
  81. state: absent
  82. key:
  83. - 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-79EA5ED4'
  84. - 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-A14FE591'
  85. - 'https://repo.zabbix.com/RPM-GPG-KEY-ZABBIX-A14FE591-EL5'
  86. when: ansible_facts['distribution_file_variety'] == 'RedHat'
  87. ignore_errors: true
  88. ########################################## Correct permissions ########################################
  89. - name: Fix permissions for /var/log/zabbix
  90. file:
  91. path: /var/log/zabbix
  92. state: directory
  93. recurse: yes
  94. owner: zabbix
  95. group: zabbix
  96. - name: Fix permissions for /etc/zabbix
  97. file:
  98. path: /etc/zabbix
  99. state: directory
  100. recurse: yes
  101. owner: zabbix
  102. group: zabbix
  103. ########################################## Start and enable zabbix-agent2.service ########################################
  104. - name: 'Start and enable zabbix-agent2.service'
  105. systemd:
  106. name: zabbix-agent2
  107. state: restart
  108. daemon_reload: true
  109. enabled: true
  110. when: ansible_facts.service_mgr == "systemd"
  111. ############################################### Debian & Ubuntu section #################################################################################################
  112. # 01-07-2025: Updated repo URLs
  113. - name: Install zabbix-release for appropriate version of Debian
  114. apt:
  115. 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"
  116. state: present
  117. when:
  118. - ansible_facts['distribution'] == 'Debian'
  119. - ansible_facts['distribution_major_version'] >= '10'
  120. - name: Install zabbix-release for appropriate version of Ubuntu
  121. apt:
  122. 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"
  123. state: present
  124. when:
  125. - ansible_facts['distribution'] == 'Ubuntu'
  126. - ansible_facts['distribution_major_version'] >= '16.04'