diff options
Diffstat (limited to 'ansible_collections/community/zabbix/molecule')
19 files changed, 291 insertions, 287 deletions
diff --git a/ansible_collections/community/zabbix/molecule/requirements.txt b/ansible_collections/community/zabbix/molecule/requirements.txt index bec205a0a..b7cbb1138 100644 --- a/ansible_collections/community/zabbix/molecule/requirements.txt +++ b/ansible_collections/community/zabbix/molecule/requirements.txt @@ -1,11 +1,13 @@ # Install CI dependencies for the Zabbix Roles ansible==7.0.0 -ansible-compat==0.5.0 +ansible-compat==3.0.0 ansible-core==2.14.2 -docker==5.0.2 -molecule==3.5.1 -molecule-docker==1.0.2 +docker==6.1.3 +molecule==4.0.4 +molecule-docker==2.1.0 netaddr==0.8.0 -pytest-testinfra==6.1.0 +pytest==7.2.1 +pytest-testinfra==7.0.0 ipaddr==2.2.0 ipaddress==1.0.23 +requests==2.31.0 diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/molecule.yml index a0222246f..a48b6ae60 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/molecule.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/molecule.yml @@ -4,8 +4,8 @@ driver: platforms: - name: zabbix-agent-${MY_MOLECULE_CONTAINER:-centos} - image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"} - command: ${MY_MOLECULE_DOCKER_COMMAND:-""} + image: geerlingguy/docker-${MY_MOLECULE_IMAGE:-rockylinux8}-ansible:latest + command: ${MOLECULE_DOCKER_COMMAND:-""} privileged: true pre_build_image: true networks: @@ -14,11 +14,10 @@ platforms: - /sys/fs/cgroup:/sys/fs/cgroup:ro groups: - agent + - ${MY_MOLECULE_VERSION:-v64} provisioner: name: ansible - lint: - name: ansible-lint playbooks: prepare: ../../common/playbooks/prepare.yml converge: ../../common/playbooks/converge.yml @@ -36,11 +35,15 @@ provisioner: zabbix_agent_listenip: 0.0.0.0 zabbix_agent_tlsconnect: psk zabbix_agent_tlsaccept: psk - + v64: + zabbix_agent_version: 6.4 + v62: + zabbix_agent_version: 6.2 + v60: + zabbix_agent_version: 6.0 scenario: test_sequence: - dependency - - lint - cleanup - destroy - syntax @@ -54,5 +57,3 @@ scenario: - destroy verifier: name: testinfra - lint: - name: flake8 diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/prepare.yml index 3ce015db6..cf1100aab 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/prepare.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/prepare.yml @@ -3,7 +3,7 @@ hosts: all tasks: - name: "Installing packages on CentOS family" - package: + ansible.builtin.package: pkg: - net-tools - which @@ -14,7 +14,7 @@ - ansible_os_family == 'RedHat' - name: "Installing packages on CentOS (Sangoma) family" - package: + ansible.builtin.package: pkg: - net-tools - which @@ -25,7 +25,7 @@ - ansible_os_family == 'Sangoma' - name: "Installing packages on Debian family" - apt: + ansible.builtin.apt: name: - "{{ 'net-tools' if ansible_distribution_major_version not in ['10','18', '20'] else 'iproute2' }}" state: present @@ -36,7 +36,7 @@ - ansible_os_family == 'Debian' - name: "Installing packages on Suse family" - shell: zypper install -y python-xml python-libxml2 net-tools which + ansible.builtin.shell: zypper install -y python-xml python-libxml2 net-tools which register: zabbix_agent_prepare_packages_install until: zabbix_agent_prepare_packages_install is succeeded when: ansible_os_family == 'Suse' @@ -47,7 +47,7 @@ hosts: docker tasks: - name: "Download Docker CE repo file" - get_url: + ansible.builtin.get_url: url: https://download.docker.com/linux/centos/docker-ce.repo dest: /etc/yum.repos.d/docker-ce.repo mode: 0644 @@ -55,7 +55,7 @@ until: zabbix_agent_prepare_docker_repo is succeeded - name: "Installing Epel" - package: + ansible.builtin.package: pkg: - epel-release state: present @@ -63,7 +63,7 @@ until: zabbix_agent_prepare_docker_install is succeeded - name: "Installing Docker" - package: + ansible.builtin.package: pkg: - docker-ce - python-pip @@ -73,7 +73,7 @@ until: zabbix_agent_prepare_docker_install is succeeded - name: "Installing Docker Python" - pip: + ansible.builtin.pip: name: - docker state: present @@ -81,6 +81,6 @@ until: zabbix_agent_prepare_docker_install is succeeded - name: "Starting Docker service" - service: + ansible.builtin.service: name: docker state: started diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/common/test_agent.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/common/test_agent.py index 96d4a1716..43d9fe244 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/common/test_agent.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/common/test_agent.py @@ -37,13 +37,13 @@ def test_socket(host): assert host.socket("tcp://0.0.0.0:10050").is_listening -def test_zabbix_package(host, zabbix_agent_package): - assert zabbix_agent_package.is_installed - - if host.system_info.distribution == "debian": - if host.system_info.codename in ["bullseye", "focal"]: - assert zabbix_agent_package.version.startswith("1:6.4") - else: - assert zabbix_agent_package.version.startswith("1:6.0") - if host.system_info.distribution == "centos": - assert zabbix_agent_package.version.startswith("6.4") +# def test_zabbix_package(host, zabbix_agent_package): +# assert zabbix_agent_package.is_installed + +# if host.system_info.distribution == "debian": +# if host.system_info.codename in ["bullseye", "focal"]: +# assert zabbix_agent_package.version.startswith("1:6.4") +# else: +# assert zabbix_agent_package.version.startswith("1:6.0") +# if host.system_info.distribution == "centos": +# assert zabbix_agent_package.version.startswith("6.4") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/common/test_agent.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/common/test_agent.py index 96d4a1716..43d9fe244 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/common/test_agent.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/common/test_agent.py @@ -37,13 +37,13 @@ def test_socket(host): assert host.socket("tcp://0.0.0.0:10050").is_listening -def test_zabbix_package(host, zabbix_agent_package): - assert zabbix_agent_package.is_installed - - if host.system_info.distribution == "debian": - if host.system_info.codename in ["bullseye", "focal"]: - assert zabbix_agent_package.version.startswith("1:6.4") - else: - assert zabbix_agent_package.version.startswith("1:6.0") - if host.system_info.distribution == "centos": - assert zabbix_agent_package.version.startswith("6.4") +# def test_zabbix_package(host, zabbix_agent_package): +# assert zabbix_agent_package.is_installed + +# if host.system_info.distribution == "debian": +# if host.system_info.codename in ["bullseye", "focal"]: +# assert zabbix_agent_package.version.startswith("1:6.4") +# else: +# assert zabbix_agent_package.version.startswith("1:6.0") +# if host.system_info.distribution == "centos": +# assert zabbix_agent_package.version.startswith("6.4") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/common/test_agent.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/common/test_agent.py index 96d4a1716..43d9fe244 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/common/test_agent.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/common/test_agent.py @@ -37,13 +37,13 @@ def test_socket(host): assert host.socket("tcp://0.0.0.0:10050").is_listening -def test_zabbix_package(host, zabbix_agent_package): - assert zabbix_agent_package.is_installed - - if host.system_info.distribution == "debian": - if host.system_info.codename in ["bullseye", "focal"]: - assert zabbix_agent_package.version.startswith("1:6.4") - else: - assert zabbix_agent_package.version.startswith("1:6.0") - if host.system_info.distribution == "centos": - assert zabbix_agent_package.version.startswith("6.4") +# def test_zabbix_package(host, zabbix_agent_package): +# assert zabbix_agent_package.is_installed + +# if host.system_info.distribution == "debian": +# if host.system_info.codename in ["bullseye", "focal"]: +# assert zabbix_agent_package.version.startswith("1:6.4") +# else: +# assert zabbix_agent_package.version.startswith("1:6.0") +# if host.system_info.distribution == "centos": +# assert zabbix_agent_package.version.startswith("6.4") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/common/test_agent.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/common/test_agent.py index 96d4a1716..43d9fe244 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/common/test_agent.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/common/test_agent.py @@ -37,13 +37,13 @@ def test_socket(host): assert host.socket("tcp://0.0.0.0:10050").is_listening -def test_zabbix_package(host, zabbix_agent_package): - assert zabbix_agent_package.is_installed - - if host.system_info.distribution == "debian": - if host.system_info.codename in ["bullseye", "focal"]: - assert zabbix_agent_package.version.startswith("1:6.4") - else: - assert zabbix_agent_package.version.startswith("1:6.0") - if host.system_info.distribution == "centos": - assert zabbix_agent_package.version.startswith("6.4") +# def test_zabbix_package(host, zabbix_agent_package): +# assert zabbix_agent_package.is_installed + +# if host.system_info.distribution == "debian": +# if host.system_info.codename in ["bullseye", "focal"]: +# assert zabbix_agent_package.version.startswith("1:6.4") +# else: +# assert zabbix_agent_package.version.startswith("1:6.0") +# if host.system_info.distribution == "centos": +# assert zabbix_agent_package.version.startswith("6.4") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/common/test_agent.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/common/test_agent.py index 96d4a1716..43d9fe244 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/common/test_agent.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/common/test_agent.py @@ -37,13 +37,13 @@ def test_socket(host): assert host.socket("tcp://0.0.0.0:10050").is_listening -def test_zabbix_package(host, zabbix_agent_package): - assert zabbix_agent_package.is_installed - - if host.system_info.distribution == "debian": - if host.system_info.codename in ["bullseye", "focal"]: - assert zabbix_agent_package.version.startswith("1:6.4") - else: - assert zabbix_agent_package.version.startswith("1:6.0") - if host.system_info.distribution == "centos": - assert zabbix_agent_package.version.startswith("6.4") +# def test_zabbix_package(host, zabbix_agent_package): +# assert zabbix_agent_package.is_installed + +# if host.system_info.distribution == "debian": +# if host.system_info.codename in ["bullseye", "focal"]: +# assert zabbix_agent_package.version.startswith("1:6.4") +# else: +# assert zabbix_agent_package.version.startswith("1:6.0") +# if host.system_info.distribution == "centos": +# assert zabbix_agent_package.version.startswith("6.4") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml index f56745b9b..ee072707d 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml @@ -3,25 +3,35 @@ driver: name: docker platforms: - - name: zabbix-javagateway-${MY_MOLECULE_CONTAINER:-centos} - image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"} - command: ${MY_MOLECULE_DOCKER_COMMAND:-""} + - name: zabbix-server-${MY_MOLECULE_CONTAINER:-centos} + image: geerlingguy/docker-${MY_MOLECULE_IMAGE:-rockylinux8}-ansible:latest privileged: true pre_build_image: true + command: ${MOLECULE_DOCKER_COMMAND:-""} networks: - name: zabbix volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro - + groups: + - ${MY_MOLECULE_VERSION:-v64} + - ${MY_MOLECULE_INTERPRETER:-python3} provisioner: name: ansible - lint: - name: ansible-lint env: ANSIBLE_COLLECTIONS_PATHS: $HOME/.ansible/collections/ansible_collections/community/zabbix ANSIBLE_ROLES_PATH: $HOME/.ansible/collections/ansible_collections/community/zabbix/roles + inventory: + group_vars: + python3: + ansible_python_interpreter: /usr/bin/python3 + python: + ansible_python_interpreter: /usr/bin/python + v64: + zabbix_javagateway_version: 6.4 + v62: + zabbix_javagateway_version: 6.2 + v60: + zabbix_javagateway_version: 6.0 verifier: name: testinfra - lint: - name: flake8 diff --git a/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml index 9d24c9f7e..3e3db6a1b 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml @@ -2,13 +2,12 @@ - name: Prepare hosts: all pre_tasks: - - name: "Set short version name" - set_fact: + ansible.builtin.set_fact: zabbix_python_prefix: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}" - name: "Installing packages on CentOS" - yum: + ansible.builtin.yum: name: - net-tools - which @@ -20,21 +19,21 @@ - ansible_os_family == 'RedHat' - name: "Make sure the docs can be installed. (Debian)" - lineinfile: + ansible.builtin.lineinfile: path: /etc/dpkg/dpkg.cfg.d/excludes state: absent - regexp: 'path-exclude=/usr/share/doc/*' + regexp: "path-exclude=/usr/share/doc/*" when: - ansible_os_family != 'RedHat' - name: Check if warn parameter can be used for shell module - set_fact: + ansible.builtin.set_fact: produce_warn: False when: ansible_version.full is version("2.14", "<") # https://github.com/geerlingguy/ansible-role-java/issues/64 - name: "Apt update" - shell: "apt-get update && mkdir -p /usr/share/man/man1" + ansible.builtin.shell: "apt-get update && mkdir -p /usr/share/man/man1" args: warn: "{{ produce_warn | default(omit) }}" register: installation_dependencies @@ -43,7 +42,7 @@ - ansible_os_family != 'RedHat' - name: "Installing packages on NON-CentOS" - apt: + ansible.builtin.apt: name: - net-tools - apt-utils @@ -53,7 +52,6 @@ - "{{ zabbix_python_prefix }}-apt" - sudo - software-properties-common - - openjdk-11-jdk update_cache: true state: present register: installation_dependencies diff --git a/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml index 21ab813c4..4eb173acf 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml @@ -1,43 +1,51 @@ --- - driver: name: docker platforms: - - name: zabbix-proxy-${MY_MOLECULE_CONTAINER:-mysql-centos} - image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"} - command: ${MY_MOLECULE_DOCKER_COMMAND:-""} + - name: zabbix-proxy-${MY_MOLECULE_CONTAINER:-centos} + image: geerlingguy/docker-${MY_MOLECULE_IMAGE:-rockylinux8}-ansible:latest privileged: true pre_build_image: true + command: ${MOLECULE_DOCKER_COMMAND:-""} networks: - name: zabbix volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro groups: - - ${MY_MOLECULE_GROUP:-mysql} + - ${MY_MOLECULE_DATABASE:-mysql} + - ${MY_MOLECULE_VERSION:-v64} provisioner: name: ansible - lint: - name: ansible-lint env: ANSIBLE_COLLECTIONS_PATHS: $HOME/.ansible/collections/ansible_collections/community/zabbix ANSIBLE_ROLES_PATH: $HOME/.ansible/collections/ansible_collections/community/zabbix/roles inventory: group_vars: + python3: + ansible_python_interpreter: /usr/bin/python3 + python: + ansible_python_interpreter: /usr/bin/python + v64: + zabbix_proxy_version: 6.4 + v62: + zabbix_proxy_version: 6.2 + v60: + zabbix_proxy_version: 6.0 mysql: + zabbix_proxy_dbname: zabbix + zabbix_proxy_dbuser: zabbix-dbuser zabbix_proxy_database: mysql - zabbix_proxy_database_long: mysql zabbix_proxy_dbport: 3306 zabbix_proxy_dbhost: mysql-host zabbix_proxy_dbhost_run_install: false - zabbix_proxy_privileged_host: '%' + zabbix_proxy_privileged_host: "%" zabbix_proxy_mysql_login_host: mysql-host zabbix_proxy_mysql_login_user: root zabbix_proxy_mysql_login_password: changeme zabbix_proxy_mysql_login_port: 3306 - postgresql: + pgsql: zabbix_proxy_database: pgsql - zabbix_proxy_database_long: postgresql zabbix_proxy_dbport: 5432 zabbix_proxy_dbhost: postgresql-host zabbix_proxy_dbhost_run_install: false @@ -49,8 +57,5 @@ provisioner: zabbix_proxy_database: sqlite3 zabbix_proxy_database_long: sqlite3 zabbix_proxy_dbname: /path/to/sqlite3.db - verifier: name: testinfra - lint: - name: flake8 diff --git a/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml index 0fc4ef320..c5e3b9e45 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml @@ -3,7 +3,6 @@ hosts: localhost connection: local pre_tasks: - - name: "Create MySQL Container" docker_container: name: mysql-host @@ -32,14 +31,13 @@ no_log: true with_items: "{{ molecule_yml.platforms }}" when: - - '"postgresql" in item.groups' + - '"pgsql" in item.groups' - name: Prepare hosts: all tasks: - - name: "Set short version name" - set_fact: + ansible.builtin.set_fact: zabbix_python_prefix: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}" - name: "Create group for imaginary host" @@ -51,7 +49,7 @@ changed_when: false - name: "Installing packages on CentOS" - yum: + ansible.builtin.yum: name: - net-tools - which @@ -62,24 +60,13 @@ when: - ansible_os_family == 'RedHat' - - name: "Installing packages on CentOS" - yum: - name: - - mysql - state: present - register: installation_dependencies - until: installation_dependencies is succeeded - when: - - ansible_os_family == 'RedHat' - - inventory_hostname in groups['mysql'] - - name: Check if warn parameter can be used for shell module - set_fact: + ansible.builtin.set_fact: produce_warn: False when: ansible_version.full is version("2.14", "<") - name: "Apt update" - shell: "apt-get update && echo exit 0 > /usr/sbin/policy-rc.d" + ansible.builtin.shell: "apt-get update && echo exit 0 > /usr/sbin/policy-rc.d" args: warn: "{{ produce_warn | default(omit) }}" register: installation_dependencies @@ -88,7 +75,7 @@ - ansible_os_family != 'RedHat' - name: "Installing packages on NON-CentOS" - apt: + ansible.builtin.apt: name: - net-tools - apt-utils @@ -104,13 +91,13 @@ - ansible_os_family != 'RedHat' - name: "Configure SUDO." - lineinfile: + ansible.builtin.lineinfile: dest: /etc/sudoers line: "Defaults !requiretty" state: present - name: "Make sure the docs can be installed. (RedHat)" - lineinfile: + ansible.builtin.lineinfile: dest: /etc/yum.conf line: "tsflags=nodocs" state: absent @@ -118,17 +105,9 @@ - ansible_os_family == 'RedHat' - name: "Make sure the docs can be installed. (Debian)" - lineinfile: + ansible.builtin.lineinfile: path: /etc/dpkg/dpkg.cfg.d/excludes state: absent - regexp: 'path-exclude=/usr/share/doc/*' + regexp: "path-exclude=/usr/share/doc/*" when: - ansible_os_family != 'RedHat' - - - name: PyMySQL - pip: - name: PyMySQL - register: installation_dependencies - until: installation_dependencies is succeeded - when: - - inventory_hostname in groups['mysql'] diff --git a/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py b/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py index 4ccbfeb4e..f96874740 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py @@ -17,28 +17,18 @@ def test_zabbixproxy_running_and_enabled(host): assert zabbix.is_running -@pytest.mark.parametrize( - "proxy", [("zabbix-proxy-pgsql"), ("zabbix-proxy-mysql"), ("zabbix-proxy-sqlite3")] -) -def test_zabbix_package(host, proxy): +def test_zabbix_package(host): ansible_data = host.ansible.get_variables() - zabbixhost = ansible_data["inventory_hostname"] + version = ansible_data['zabbix_proxy_version'] + database = ansible_data['zabbix_proxy_database'] - zabbixhost = zabbixhost.replace("-centos", "") - zabbixhost = zabbixhost.replace("-debian", "") - zabbixhost = zabbixhost.replace("-ubuntu", "") - - if zabbixhost == proxy: - zabbix_proxy = host.package(proxy) - if host.system_info.distribution in ["debian", "ubuntu"]: - assert zabbix_proxy.version.startswith("1:6.4") - elif host.system_info.distribution == "centos": - assert zabbix_proxy.version.startswith("6.4") - assert zabbix_proxy.is_installed + zabbix_proxy = host.package(f'zabbix-proxy-%s' % database) + assert str(version) in zabbix_proxy.version def test_zabbix_proxy_dot_conf(host): zabbix_proxy_conf = host.file("/etc/zabbix/zabbix_proxy.conf") + assert zabbix_proxy_conf.exists assert zabbix_proxy_conf.user == "zabbix" assert zabbix_proxy_conf.group == "zabbix" assert zabbix_proxy_conf.mode == 0o644 @@ -52,13 +42,13 @@ def test_zabbix_include_dir(host): assert zabbix_include_dir.is_directory assert zabbix_include_dir.user == "zabbix" assert zabbix_include_dir.group == "zabbix" - # assert zabbix_include_dir.mode == 0o644 def test_zabbix_proxy_logfile(host): zabbix_logfile = host.file("/var/log/zabbix/zabbix_proxy.log") - + assert zabbix_logfile.exists assert not zabbix_logfile.contains("Access denied for user") assert not zabbix_logfile.contains("database is down: reconnecting") + assert not zabbix_logfile.contains("Both are missing in the system.") # Missing fping assert zabbix_logfile.contains("current database version") assert zabbix_logfile.contains(r"proxy #0 started \[main process\]") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml index 4fa0a8daa..2424455f4 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml @@ -1,43 +1,54 @@ --- - driver: name: docker platforms: - - name: zabbix-server-${MY_MOLECULE_CONTAINER:-mysql-centos} - image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"} - command: ${MY_MOLECULE_DOCKER_COMMAND:-""} + - name: zabbix-server-${MY_MOLECULE_CONTAINER:-centos} + image: geerlingguy/docker-${MY_MOLECULE_IMAGE:-rockylinux8}-ansible:latest privileged: true pre_build_image: true + command: ${MOLECULE_DOCKER_COMMAND:-""} networks: - name: zabbix volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro groups: - - ${MY_MOLECULE_GROUP:-mysql} + - ${MY_MOLECULE_DATABASE:-mysql} + - ${MY_MOLECULE_VERSION:-v64} + - ${MY_MOLECULE_INTERPRETER:-python3} provisioner: name: ansible - lint: - name: ansible-lint env: ANSIBLE_COLLECTIONS_PATHS: $HOME/.ansible/collections/ansible_collections/community/zabbix ANSIBLE_ROLES_PATH: $HOME/.ansible/collections/ansible_collections/community/zabbix/roles inventory: group_vars: + python3: + ansible_python_interpreter: /usr/bin/python3 + python: + ansible_python_interpreter: /usr/bin/python + v64: + zabbix_server_version: 6.4 + v62: + zabbix_server_version: 6.2 + v60: + zabbix_server_version: 6.0 + v50: + zabbix_server_version: 5.0 mysql: + zabbix_server_dbname: zabbix + zabbix_server_dbuser: zabbix-dbuser zabbix_server_database: mysql - zabbix_server_database_long: mysql zabbix_server_dbport: 3306 zabbix_server_dbhost: mysql-host zabbix_server_dbhost_run_install: false - zabbix_server_privileged_host: '%' + zabbix_server_privileged_host: "%" zabbix_server_mysql_login_host: mysql-host zabbix_server_mysql_login_user: root zabbix_server_mysql_login_password: changeme zabbix_server_mysql_login_port: 3306 - postgresql: + pgsql: zabbix_server_database: pgsql - zabbix_server_database_long: postgresql zabbix_server_dbport: 5432 zabbix_server_dbhost: postgresql-host zabbix_server_dbhost_run_install: false @@ -48,5 +59,3 @@ provisioner: verifier: name: testinfra - lint: - name: flake8 diff --git a/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml index 51945c066..922b33753 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml @@ -3,11 +3,10 @@ hosts: localhost connection: local pre_tasks: - - name: "Create MySQL Container" docker_container: name: mysql-host - image: mysql:8.0 + image: mysql:8.0.32 state: started recreate: true networks: @@ -32,12 +31,11 @@ no_log: true with_items: "{{ molecule_yml.platforms }}" when: - - '"postgresql" in item.groups' + - '"pgsql" in item.groups' - name: Prepare hosts: all tasks: - - name: "Create group for imaginary host" add_host: name: imaginary-host @@ -47,7 +45,7 @@ changed_when: false - name: "Installing packages on CentOS" - yum: + ansible.builtin.yum: name: - net-tools - which @@ -59,7 +57,7 @@ - ansible_os_family == 'RedHat' - name: "Installing packages on CentOS" - yum: + ansible.builtin.yum: name: - mysql state: present @@ -70,12 +68,12 @@ - inventory_hostname in groups['mysql'] - name: Check if warn parameter can be used for shell module - set_fact: - produce_warn: False + ansible.builtin.set_fact: + produce_warn: false when: ansible_version.full is version("2.14", "<") - name: "Apt update" - shell: "apt-get update && echo exit 0 > /usr/sbin/policy-rc.d" + ansible.builtin.shell: "apt-get update && echo exit 0 > /usr/sbin/policy-rc.d" args: warn: "{{ produce_warn | default(omit) }}" register: installation_dependencies @@ -84,7 +82,7 @@ - ansible_os_family != 'RedHat' - name: "Installing packages on NON-CentOS" - apt: + ansible.builtin.apt: name: - net-tools - apt-utils @@ -99,13 +97,13 @@ - ansible_os_family != 'RedHat' - name: "Configure SUDO." - lineinfile: + ansible.builtin.lineinfile: dest: /etc/sudoers line: "Defaults !requiretty" state: present - name: "Make sure the docs are installed." - lineinfile: + ansible.builtin.lineinfile: dest: /etc/yum.conf line: "tsflags=nodocs" state: absent @@ -113,7 +111,7 @@ - ansible_os_family == 'RedHat' - name: PyMySQL - pip: + ansible.builtin.pip: name: PyMySQL register: installation_dependencies until: installation_dependencies is succeeded diff --git a/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py b/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py index 9a119d5ac..ee43ad2a3 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py @@ -1,5 +1,7 @@ import os import pytest +from pathlib import Path + import testinfra.utils.ansible_runner @@ -17,26 +19,18 @@ def test_zabbiserver_running_and_enabled(host): assert zabbix.is_running -@pytest.mark.parametrize("server", [("zabbix-server-pgsql"), ("zabbix-server-mysql")]) -def test_zabbix_package(host, server): +def test_zabbix_package(host): ansible_data = host.ansible.get_variables() - zabbixhost = ansible_data["inventory_hostname"] - - zabbixhost = zabbixhost.replace("-centos", "") - zabbixhost = zabbixhost.replace("-debian", "") - zabbixhost = zabbixhost.replace("-ubuntu", "") + version = ansible_data['zabbix_server_version'] + database = ansible_data['zabbix_server_database'] - if zabbixhost == server: - zabbix_server = host.package(server) - if host.system_info.distribution in ["debian", "ubuntu"]: - assert zabbix_server.version.startswith("1:6.4") - elif host.system_info.distribution == "centos": - assert zabbix_server.version.startswith("6.4") - assert zabbix_server.is_installed + zabbix_server = host.package(f'zabbix-server-%s' % database) + assert str(version) in zabbix_server.version def test_zabbix_server_dot_conf(host): zabbix_server_conf = host.file("/etc/zabbix/zabbix_server.conf") + assert zabbix_server_conf.exists assert zabbix_server_conf.user == "zabbix" assert zabbix_server_conf.group == "zabbix" assert zabbix_server_conf.mode == 0o640 @@ -50,13 +44,13 @@ def test_zabbix_include_dir(host): assert zabbix_include_dir.is_directory assert zabbix_include_dir.user == "zabbix" assert zabbix_include_dir.group == "zabbix" - # assert zabbix_include_dir.mode == 0o644 def test_zabbix_server_logfile(host): zabbix_logfile = host.file("/var/log/zabbix/zabbix_server.log") - + assert zabbix_logfile.exists assert not zabbix_logfile.contains("Access denied for user") assert not zabbix_logfile.contains("database is down: reconnecting") + assert not zabbix_logfile.contains("Both are missing in the system.") # Missing fping assert zabbix_logfile.contains("current database version") assert zabbix_logfile.contains(r"server #0 started \[main process\]") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml index baffecc47..0aa3ab800 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml @@ -10,30 +10,45 @@ dependency: driver: name: docker platforms: - - name: zabbix-web-${MY_MOLECULE_CONTAINER:-mysql-centos8} - image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"} - command: ${MY_MOLECULE_DOCKER_COMMAND:-""} + - name: zabbix-web-${MY_MOLECULE_CONTAINER:-centos} + image: geerlingguy/docker-${MY_MOLECULE_IMAGE:-rockylinux8}-ansible:latest privileged: true pre_build_image: true + command: ${MOLECULE_DOCKER_COMMAND:-""} networks: - name: zabbix volumes: - /sys/fs/cgroup:/sys/fs/cgroup:ro groups: - - ${MY_MOLECULE_GROUP:-mysql} + - ${MY_MOLECULE_DATABASE:-mysql} + - ${MY_MOLECULE_VERSION:-v64} + - ${MY_MOLECULE_INTERPRETER:-python3} + - ${MY_MOLECULE_WEB_SERVER:-apache} provisioner: name: ansible - lint: - name: ansible-lint env: ANSIBLE_COLLECTIONS_PATHS: $HOME/.ansible/collections/ansible_collections/community/zabbix ANSIBLE_ROLES_PATH: $HOME/.ansible/collections/ansible_collections/community/zabbix/roles inventory: group_vars: + all: + zabbix_api_server_url: zabbix-web-${MY_MOLECULE_CONTAINER:-centos} + python3: + ansible_python_interpreter: /usr/bin/python3 + python: + ansible_python_interpreter: /usr/bin/python + v64: + zabbix_server_version: 6.4 + zabbix_web_version: 6.4 + v62: + zabbix_server_version: 6.2 + zabbix_web_version: 6.2 + v60: + zabbix_server_version: 6.0 + zabbix_web_version: 6.0 mysql: zabbix_server_database: mysql - zabbix_server_database_long: mysql zabbix_server_dbport: 3306 zabbix_server_dbhost: mysql-host zabbix_server_dbhost_run_install: false @@ -42,9 +57,8 @@ provisioner: zabbix_server_mysql_login_user: root zabbix_server_mysql_login_password: changeme zabbix_server_mysql_login_port: 3306 - postgresql: + pgsql: zabbix_server_database: pgsql - zabbix_server_database_long: postgresql zabbix_server_dbport: 5432 zabbix_server_dbhost: postgresql-host zabbix_server_dbhost_run_install: false @@ -52,44 +66,11 @@ provisioner: zabbix_server_pgsql_login_user: postgres zabbix_server_pgsql_login_password: changeme zabbix_server_pgsql_login_port: 5432 - host_vars: - zabbix-web-pgsql-debian: - zabbix_websrv: apache - zabbix_php_fpm_conf_listen: false - zabbix_api_server_url: zabbix-web-pgsql-debian - zabbix_websrv_servername: zabbix-web-pgsql-debian - zabbix-web-mysql-debian: - zabbix_websrv: apache - zabbix_php_fpm_conf_listen: false - zabbix_api_server_url: zabbix-web-mysql-debian - zabbix_websrv_servername: zabbix-web-mysql-debian - zabbix-web-pgsql-centos8: - ansible_rhn_repo_disable_gpg_check: true - zabbix_websrv: apache - zabbix_php_fpm_conf_listen: false - zabbix_api_server_url: zabbix-web-pgsql-centos8 - zabbix_websrv_servername: zabbix-web-pgsql-centos8 - zabbix-web-mysql-centos8: - ansible_rhn_repo_disable_gpg_check: true - php_fpm_pool_user: nginx - php_fpm_pool_group: nginx - zabbix_websrv: nginx - zabbix_php_fpm_conf_listen: false - zabbix_api_server_url: zabbix-web-mysql-centos8 - zabbix_websrv_servername: zabbix-web-mysql-centos8 - zabbix-web-mysql-ubuntu18: - zabbix_websrv: nginx - zabbix_php_fpm_conf_listen: false - zabbix_api_server_url: zabbix-web-mysql-ubuntu18 - zabbix_websrv_servername: zabbix-web-mysql-ubuntu18 + apache: + zabbix_web_http_server: apache + nginx: + zabbix_web_http_server: nginx php_webserver_daemon: nginx - zabbix-web-pgsql-ubuntu20: - zabbix_php_fpm_conf_listen: false - zabbix_websrv: apache - zabbix_api_server_url: zabbix-web-pgsql-ubuntu20 - zabbix_websrv_servername: zabbix-web-pgsql-ubuntu20 verifier: name: testinfra - lint: - name: flake8 diff --git a/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml index 3c0c6db86..204eb8f56 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml @@ -31,7 +31,7 @@ no_log: true with_items: "{{ molecule_yml.platforms }}" when: - - '"postgresql" in item.groups' + - '"pgsql" in item.groups' - name: Prepare hosts: all @@ -45,14 +45,11 @@ changed_when: false - name: "Installing packages on CentOS" - yum: + ansible.builtin.yum: name: - net-tools - which - - curl - sudo - - "{{ 'python3-pip' if ansible_distribution_major_version == '8' else 'python-pip' }}" - - "{{ 'python3-libselinux' if ansible_distribution_major_version == '8' else 'libselinux-python' }}" state: present register: installation_dependencies until: installation_dependencies is succeeded @@ -60,7 +57,7 @@ - ansible_os_family == 'RedHat' - name: "Installing packages (CentOS7)" - yum: + ansible.builtin.yum: name: - centos-release-scl state: present @@ -70,7 +67,7 @@ - ansible_distribution_major_version == '7' - name: "Installing MySQL on CentOS" - yum: + ansible.builtin.yum: name: - mysql state: present @@ -80,20 +77,29 @@ - ansible_os_family == 'RedHat' - inventory_hostname in groups['mysql'] + - name: Check if warn parameter can be used for shell module + ansible.builtin.set_fact: + produce_warn: false + when: ansible_version.full is version("2.14", "<") + + - name: "Apt update" + ansible.builtin.shell: "apt-get update && echo exit 0 > /usr/sbin/policy-rc.d" + args: + warn: "{{ produce_warn | default(omit) }}" + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' + - name: "Installing packages on NON-CentOS" - apt: + ansible.builtin.apt: name: - net-tools - - curl - apt-utils - - apt-transport-https - - ca-certificates - - gnupg2 + - python3-pip - gpg-agent - sudo - - vim - - "{{ 'python3-apt' if ansible_distribution_major_version in ['10', '11', '18', '20'] else 'python-apt' }}" - - "{{ 'python3-pip' if ansible_distribution_major_version in ['10', '11', '18', '20'] else 'python-pip' }}" + - curl update_cache: true state: present register: installation_dependencies @@ -102,13 +108,13 @@ - ansible_os_family != 'RedHat' - name: "Configure SUDO." - lineinfile: + ansible.builtin.lineinfile: dest: /etc/sudoers line: "Defaults !requiretty" state: present - name: "Make sure the docs are installed." - lineinfile: + ansible.builtin.lineinfile: dest: /etc/yum.conf line: "tsflags=nodocs" state: absent @@ -116,7 +122,7 @@ - ansible_os_family == 'RedHat' - name: PyMySQL - pip: + ansible.builtin.pip: name: PyMySQL register: installation_dependencies until: installation_dependencies is succeeded @@ -124,26 +130,72 @@ - inventory_hostname in groups['mysql'] - name: Enabeling PHP 7.4 - command: dnf module enable php:7.4 -y + ansible.builtin.command: dnf module enable php:7.4 -y when: - ansible_os_family == 'RedHat' - ansible_distribution_major_version == "8" + - name: Set PHP packages (Centos 8+) + ansible.builtin.set_fact: + php_packages: + - php + - php-cli + - php-common + - php-devel + - php-fpm + - php-gd + - php-ldap + - php-mbstring + - php-opcache + - php-pdo + - php-pear + - php-pecl-apcu + - php-xml + when: + - ansible_distribution_major_version >= '8' + - ansible_os_family == "RedHat" + + - name: Set PHP Version (Ubuntu 2204) + ansible.builtin.set_fact: + __php_default_version_debian: "8.1" + when: + - ansible_distribution_major_version >= '22' + - ansible_os_family == "Debian" + + - name: Set PHP packages (Ubuntu 2204) + ansible.builtin.set_fact: + __php_packages: + - php{{ __php_default_version_debian }}-common + - php{{ __php_default_version_debian }}-cli + - php{{ __php_default_version_debian }}-dev + - php{{ __php_default_version_debian }}-fpm + - libpcre3-dev + - php{{ __php_default_version_debian }}-gd + - php{{ __php_default_version_debian }}-curl + - php{{ __php_default_version_debian }}-imap + - php-json + - php{{ __php_default_version_debian }}-opcache + - php{{ __php_default_version_debian }}-xml + - php{{ __php_default_version_debian }}-mbstring + - php{{ __php_default_version_debian }}-apcu + - php{{ __php_default_version_debian }}-sqlite3 + when: + - ansible_distribution_major_version >= '22' + - ansible_os_family == "Debian" + roles: - role: geerlingguy.apache when: - - zabbix_websrv == "apache" + - zabbix_web_http_server == "apache" - role: geerlingguy.nginx when: - - zabbix_websrv == "nginx" + - zabbix_web_http_server == "nginx" - role: geerlingguy.php - when: - - ansible_os_family != 'RedHat' or (ansible_os_family == 'RedHat' and ansible_distribution_major_version == "8") - role: zabbix_server post_tasks: - name: "Remove file" - file: + ansible.builtin.file: path: "{{ item }}" state: absent with_items: diff --git a/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py b/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py index a6f7527b0..f4882b97b 100644 --- a/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py @@ -8,34 +8,19 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( ).get_hosts("all") -@pytest.mark.parametrize( - "server, redhat, debian", - [ - ("zabbix-server-pgsql", "zabbix-web-pgsql", "zabbix-frontend-php"), - ("zabbix-server-mysql", "zabbix-web-mysql", "zabbix-frontend-php"), - ], -) -def test_zabbix_package(host, server, redhat, debian): - host = host.backend.get_hostname() - host = host.replace("-centos7", "") - host = host.replace("-centos8", "") - host = host.replace("-debian", "") - host = host.replace("-ubuntu", "") +def test_zabbix_package(host): + ansible_data = host.ansible.get_variables() + version = ansible_data['zabbix_web_version'] + webserver = ansible_data['zabbix_web_http_server'] - if host == server: - if host.system_info.distribution in ["debian", "ubuntu"]: - zabbix_web = host.package(debian) - assert zabbix_web.version.startswith("1:6.4") - elif host.system_info.distribution == "centos": - zabbix_web = host.package(redhat) - assert zabbix_web.version.startswith("6.4") - assert zabbix_web.is_installed + zabbix_web = host.package(f'zabbix-%s-conf' % webserver) + assert str(version) in zabbix_web.version def test_zabbix_web(host): zabbix_web = host.file("/etc/zabbix/web/zabbix.conf.php") ansible_variables = host.ansible.get_variables() - zabbix_websrv = str(ansible_variables["zabbix_websrv"]) + zabbix_websrv = str(ansible_variables["zabbix_web_http_server"]) if host.system_info.distribution in ["debian", "ubuntu"]: assert zabbix_web.user == "www-data" @@ -47,7 +32,7 @@ def test_zabbix_web(host): elif zabbix_websrv == "nginx": assert zabbix_web.user == "nginx" assert zabbix_web.group == "nginx" - assert zabbix_web.mode == 0o640 + assert zabbix_web.mode == 0o644 def test_zabbix_api(host): |