From 57c36e037815b6344c24922c069b6e0b2d0bcc71 Mon Sep 17 00:00:00 2001 From: Dusan Matejka Date: Fri, 25 Oct 2019 12:28:20 +0200 Subject: [PATCH] Zabbix integration tests (#63744) * adjusted setup_zabbix integration tests role to work on distributions from Debian family * bumped zabbix_host integration tests role to be run against bionic --- .../targets/setup_zabbix/defaults/main.yml | 4 +- .../targets/setup_zabbix/tasks/main.yml | 5 +- .../targets/setup_zabbix/tasks/setup.yml | 68 +++++++++++++++---- .../templates/zabbix_server.conf.j2 | 1 + .../targets/zabbix_host/tasks/main.yml | 23 ++++--- 5 files changed, 70 insertions(+), 31 deletions(-) diff --git a/test/integration/targets/setup_zabbix/defaults/main.yml b/test/integration/targets/setup_zabbix/defaults/main.yml index 55c963e627f..0a1664754bb 100644 --- a/test/integration/targets/setup_zabbix/defaults/main.yml +++ b/test/integration/targets/setup_zabbix/defaults/main.yml @@ -3,7 +3,9 @@ db_name: 'zabbix' db_user: 'zabbix' db_password: 'fLhijUs3PgekNhwJ' -zabbix_release_deb: 'http://repo.zabbix.com/zabbix/3.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.4-1+trusty_all.deb' +zabbix_version: 4.0 +zabbix_apt_repository: 'deb http://repo.zabbix.com/zabbix/{{ zabbix_version }}/{{ ansible_distribution.lower() }}/ {{ ansible_distribution_release }} main' +zabbix_apt_repository_key: 'http://repo.zabbix.com/zabbix-official-repo.key' zabbix_packages: - zabbix-server-mysql diff --git a/test/integration/targets/setup_zabbix/tasks/main.yml b/test/integration/targets/setup_zabbix/tasks/main.yml index 7a6a71ca060..6d082fff219 100644 --- a/test/integration/targets/setup_zabbix/tasks/main.yml +++ b/test/integration/targets/setup_zabbix/tasks/main.yml @@ -1,6 +1,3 @@ --- - -# This integration test is only for Ubuntu 14.04 at the moment. This makes -# installation of a Zabbix quite a bit easier. - include: setup.yml - when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty' + when: ansible_os_family == 'Debian' diff --git a/test/integration/targets/setup_zabbix/tasks/setup.yml b/test/integration/targets/setup_zabbix/tasks/setup.yml index 92d5eb811fb..b3d31e5a46d 100644 --- a/test/integration/targets/setup_zabbix/tasks/setup.yml +++ b/test/integration/targets/setup_zabbix/tasks/setup.yml @@ -1,23 +1,47 @@ -# sets up and starts Zabbix with default settings (works on Ubuntu 14.04, -# possibly more) using a MySQL database. +# sets up and starts Zabbix with default settings using a MySQL database. -- name: create mysql user {{ db_user }} - mysql_user: - name: "{{ db_user }}" - password: "{{ db_password }}" +- name: install zabbix repository key + apt_key: + url: "{{ zabbix_apt_repository_key }}" state: present - priv: "{{ db_name }}.*:ALL" - name: install zabbix repository - apt: deb={{ zabbix_release_deb }} state=present + apt_repository: + repo: "{{ zabbix_apt_repository }}" + filename: zabbix + state: present -- name: install zabbix debian dependencies - apt: name={{ item }} state=latest update_cache=yes - with_items: "{{ zabbix_packages }}" +- name: check if dpkg is set to exclude specific destinations + stat: + path: /etc/dpkg/dpkg.cfg.d/excludes + register: dpkg_excludes + +- name: ensure documentation installations are allowed for zabbix + lineinfile: + path: /etc/dpkg/dpkg.cfg.d/excludes + regexp: '^path-include=/usr/share/doc/zabbix*$' + line: 'path-include=/usr/share/doc/zabbix*' + state: present + when: dpkg_excludes.stat.exists + +- name: install zabbix apt dependencies + apt: + name: "{{ zabbix_packages }}" + state: latest + update_cache: yes - name: install zabbix-api python package pip: name: zabbix-api + state: latest + +- name: create mysql user {{ db_user }} + mysql_user: + name: "{{ db_user }}" + password: "{{ db_password }}" + state: present + priv: "{{ db_name }}.*:ALL" + login_unix_socket: '{{ mysql_socket }}' - name: import initial zabbix database mysql_db: @@ -31,9 +55,9 @@ template: src: zabbix_server.conf.j2 dest: /etc/zabbix/zabbix_server.conf - owner: zabbix + owner: root group: zabbix - mode: 0644 + mode: 0640 - name: deploy zabbix web frontend configuration template: @@ -41,8 +65,22 @@ dest: /etc/zabbix/web/zabbix.conf.php mode: 0644 +- name: Create proper run directory for zabbix-server + file: + path: /var/run/zabbix + state: directory + owner: zabbix + group: zabbix + mode: 0775 + - name: restart zabbix-server - service: name=zabbix-server state=restarted enabled=yes + service: + name: zabbix-server + state: restarted + enabled: yes - name: restart apache2 - service: name=apache2 state=restarted enabled=yes + service: + name: apache2 + state: restarted + enabled: yes diff --git a/test/integration/targets/setup_zabbix/templates/zabbix_server.conf.j2 b/test/integration/targets/setup_zabbix/templates/zabbix_server.conf.j2 index 672c6332a02..f4c201af594 100644 --- a/test/integration/targets/setup_zabbix/templates/zabbix_server.conf.j2 +++ b/test/integration/targets/setup_zabbix/templates/zabbix_server.conf.j2 @@ -1,3 +1,4 @@ +PidFile=/var/run/zabbix/zabbix_server.pid LogFile=/tmp/zabbix_server.log DBName={{ db_name }} DBUser={{ db_user }} diff --git a/test/integration/targets/zabbix_host/tasks/main.yml b/test/integration/targets/zabbix_host/tasks/main.yml index c3396bc9fa0..51c35a71735 100644 --- a/test/integration/targets/zabbix_host/tasks/main.yml +++ b/test/integration/targets/zabbix_host/tasks/main.yml @@ -1,16 +1,17 @@ --- # setup stuff not testing zabbix_host -- include: zabbix_host_setup.yml - when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty' +- block: + - include: zabbix_host_setup.yml -# zabbix_host module tests -- include: zabbix_host_tests.yml - when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty' + # zabbix_host module tests + - include: zabbix_host_tests.yml -# documentation example tests -- include: zabbix_host_doc.yml - when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty' + # documentation example tests + - include: zabbix_host_doc.yml -# tear down stuff set up earlier -- include: zabbix_host_teardown.yml - when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'trusty' + # tear down stuff set up earlier + - include: zabbix_host_teardown.yml + + when: + - ansible_distribution == 'Ubuntu' + - ansible_distribution_release == 'bionic'