From a453ac31f3428614cceb99027f8efbdb9258a40b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 14 May 2024 22:03:01 +0200 Subject: Adding upstream version 2.10.7+merged+base+2.10.8+dfsg. Signed-off-by: Daniel Baumann --- .../community/zabbix/molecule/requirements.txt | 11 ++ .../zabbix/molecule/zabbix_agent/converge.yml | 5 + .../zabbix/molecule/zabbix_agent/molecule.yml | 71 ++++++++++ .../zabbix/molecule/zabbix_agent/prepare.yml | 86 ++++++++++++ .../molecule/zabbix_agent/tests/test_agent.py | 66 ++++++++++ .../molecule/zabbix_agent/tests/test_agent2.py | 67 ++++++++++ .../molecule/zabbix_agent/tests/test_docker.py | 22 ++++ .../molecule/zabbix_javagateway/converge.yml | 6 + .../molecule/zabbix_javagateway/molecule.yml | 27 ++++ .../zabbix/molecule/zabbix_javagateway/prepare.yml | 57 ++++++++ .../zabbix_javagateway/tests/test_default.py | 23 ++++ .../zabbix/molecule/zabbix_proxy/converge.yml | 4 + .../zabbix/molecule/zabbix_proxy/destroy.yml | 25 ++++ .../zabbix/molecule/zabbix_proxy/molecule.yml | 56 ++++++++ .../zabbix/molecule/zabbix_proxy/prepare.yml | 129 ++++++++++++++++++ .../molecule/zabbix_proxy/tests/test_default.py | 62 +++++++++ .../zabbix/molecule/zabbix_server/converge.yml | 5 + .../zabbix/molecule/zabbix_server/destroy.yml | 25 ++++ .../zabbix/molecule/zabbix_server/molecule.yml | 52 ++++++++ .../zabbix/molecule/zabbix_server/prepare.yml | 116 ++++++++++++++++ .../molecule/zabbix_server/tests/test_default.py | 62 +++++++++ .../zabbix/molecule/zabbix_web/converge.yml | 5 + .../zabbix/molecule/zabbix_web/destroy.yml | 25 ++++ .../zabbix/molecule/zabbix_web/molecule.yml | 96 ++++++++++++++ .../zabbix/molecule/zabbix_web/prepare.yml | 146 +++++++++++++++++++++ .../zabbix/molecule/zabbix_web/requirements.yml | 5 + .../molecule/zabbix_web/tests/test_default.py | 58 ++++++++ 27 files changed, 1312 insertions(+) create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/requirements.txt create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/converge.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/molecule.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/prepare.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent.py create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent2.py create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_docker.py create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/converge.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/tests/test_default.py create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/converge.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/destroy.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/converge.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/destroy.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/converge.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/destroy.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/requirements.yml create mode 100644 collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py (limited to 'collections-debian-merged/ansible_collections/community/zabbix/molecule') diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/requirements.txt b/collections-debian-merged/ansible_collections/community/zabbix/molecule/requirements.txt new file mode 100644 index 00000000..8ed19f2d --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/requirements.txt @@ -0,0 +1,11 @@ +# Install CI dependencies for the Zabbix Roles +ansible==2.10.4 +ansible-lint==4.3.7 +docker==4.3.1 +molecule==3.2.1 +molecule-docker==0.2.4 +netaddr==0.8.0 +pytest-testinfra==6.1.0 +zabbix-api==0.5.4 +ipaddr==2.2.0 +ipaddress==1.0.23 diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/converge.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/converge.yml new file mode 100644 index 00000000..7ce55d49 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: zabbix_agent diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/molecule.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/molecule.yml new file mode 100644 index 00000000..865333b9 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/molecule.yml @@ -0,0 +1,71 @@ +--- +driver: + name: docker + +platforms: + - name: zabbix-agent-${MY_MOLECULE_CONTAINER:-centos} + image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"} + command: ${MY_MOLECULE_DOCKER_COMMAND:-""} + privileged: True + pre_build_image: True + networks: + - name: zabbix + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + groups: + - ${MY_MOLECULE_GROUP:-agent} + +provisioner: + name: ansible + lint: + name: ansible-lint + env: + ANSIBLE_REMOTE_TMP: /tmp/ + ANSIBLE_COLLECTIONS_PATHS: $HOME/.ansible/collections/ansible_collections/community/zabbix + ANSIBLE_ROLES_PATH: $HOME/.ansible/collections/ansible_collections/community/zabbix/roles + inventory: + host_vars: + zabbix-agent-centos2: + zabbix_agent2: true + zabbix_agent2_tlsconnect: psk + zabbix_agent2_tlsaccept: psk + zabbix_agent2_tlspskidentity: my_Identity + zabbix_agent2_tlspskfile: /data/certs/zabbix.psk + zabbix_agent2_tlspsk_secret: 97defd6bd126d5ba7fa5f296595f82eac905d5eda270207a580ab7c0cb9e8eab + zabbix_agent2_plugins: + - name: SystemRun + options: + - parameter: LogRemoteCommands + value: 0 + group_vars: + all: + zabbix_agent_src_reinstall: False + zabbix_install_pip_packages: False + zabbix_agent_server: 192.168.3.33 + zabbix_agent_serveractive: 192.168.3.33 + zabbix_agent_listenip: 0.0.0.0 + zabbix_agent_tlsconnect: psk + zabbix_agent_tlsaccept: psk + zabbix_agent_tlspskidentity: my_Identity + zabbix_agent_tlspskfile: /data/certs/zabbix.psk + zabbix_agent_tlspsk_secret: 97defd6bd126d5ba7fa5f296595f82eac905d5eda270207a580ab7c0cb9e8eab + +scenario: + test_sequence: + - dependency + - lint + - cleanup + - destroy + - syntax + - create + - prepare + - converge + # - idempotence + - side_effect + - verify + - cleanup + - destroy +verifier: + name: testinfra + lint: + name: flake8 diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/prepare.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/prepare.yml new file mode 100644 index 00000000..73a3385c --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/prepare.yml @@ -0,0 +1,86 @@ +--- + +- name: Prepare + hosts: all + tasks: + - name: "Installing packages on CentOS family" + package: + pkg: + - net-tools + - which + state: present + register: zabbix_agent_prepare_packages_install + until: zabbix_agent_prepare_packages_install is succeeded + when: + - ansible_os_family == 'RedHat' + + - name: "Installing packages on CentOS (Sangoma) family" + package: + pkg: + - net-tools + - which + state: present + register: zabbix_agent_prepare_packages_install + until: zabbix_agent_prepare_packages_install is succeeded + when: + - ansible_os_family == 'Sangoma' + + - name: "Installing packages on Debian family" + apt: + name: + - "{{ 'net-tools' if ansible_distribution_major_version not in ['18', '20'] else 'iproute2' }}" + state: present + register: zabbix_agent_prepare_packages_install + until: zabbix_agent_prepare_packages_install is succeeded + when: + - ansible_os_family == 'Debian' + + - name: "Installing packages on Suse family" + 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' + tags: + - skip_ansible_lint + +- name: Prepare + hosts: docker + tasks: + - name: "Download Docker CE repo file" + get_url: + url: https://download.docker.com/linux/centos/docker-ce.repo + dest: /etc/yum.repos.d/docker-ce.repo + mode: 0644 + register: zabbix_agent_prepare_docker_repo + until: zabbix_agent_prepare_docker_repo is succeeded + + - name: "Installing Epel" + package: + pkg: + - epel-release + state: present + register: zabbix_agent_prepare_docker_install + until: zabbix_agent_prepare_docker_install is succeeded + + - name: "Installing Docker" + package: + pkg: + - docker-ce + - python-pip + - python-setuptools + state: present + register: zabbix_agent_prepare_docker_install + until: zabbix_agent_prepare_docker_install is succeeded + + - name: "Installing Docker Python" + pip: + name: + - docker + state: present + register: zabbix_agent_prepare_docker_install + until: zabbix_agent_prepare_docker_install is succeeded + + - name: "Starting Docker service" + service: + name: docker + state: started diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent.py b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent.py new file mode 100644 index 00000000..bb4a8586 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent.py @@ -0,0 +1,66 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('agent') + + +def test_zabbixagent_running_and_enabled(host): + zabbixagent = host.service("zabbix-agent") + # Find out why this is not working for linuxmint and opensuse + if host.system_info.distribution not in ['linuxmint', 'opensuse', 'ubuntu']: + assert zabbixagent.is_running + assert zabbixagent.is_enabled + + +def test_zabbix_agent_dot_conf(host): + if host.system_info.distribution in ['opensuse']: + passwd = host.file("/etc/zabbix/zabbix-agentd.conf") + else: + passwd = host.file("/etc/zabbix/zabbix_agentd.conf") + assert passwd.user == "root" + assert passwd.group == "root" + assert passwd.mode == 0o644 + + assert passwd.contains("Server=192.168.3.33") + assert passwd.contains("ServerActive=192.168.3.33") + assert passwd.contains("DebugLevel=3") + assert passwd.contains("TLSAccept=psk") + assert passwd.contains("TLSPSKIdentity=my_Identity") + assert passwd.contains("TLSPSKFile=/data/certs/zabbix.psk") + + +def test_zabbix_agent_psk(host): + psk_file = host.file("/data/certs/zabbix.psk") + assert psk_file.user == "zabbix" + assert psk_file.group == "zabbix" + assert psk_file.mode == 0o400 + assert psk_file.contains("97defd6bd126d5ba7fa5f296595f82eac905d5eda270207a580ab7c0cb9e8eab") + + +def test_zabbix_include_dir(host): + zabbixagent = host.file("/etc/zabbix/zabbix_agentd.d") + assert zabbixagent.is_directory + assert zabbixagent.user == "root" + assert zabbixagent.group == "zabbix" + + +def test_socket(host): + # Find out why this is not working for linuxmint and opensus + if host.system_info.distribution not in ['linuxmint', 'opensuse']: + assert host.socket("tcp://0.0.0.0:10050").is_listening + + +@pytest.mark.parametrize("zabbix_packages", [ + ("zabbix-agent"), +]) +def test_zabbix_package(host, zabbix_packages): + zabbixagent = host.package(zabbix_packages) + assert zabbixagent.is_installed + + if host.system_info.distribution == 'debian': + assert zabbixagent.version.startswith("1:5.2") + if host.system_info.distribution == 'centos': + assert zabbixagent.version.startswith("5.2") diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent2.py b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent2.py new file mode 100644 index 00000000..156304bf --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_agent2.py @@ -0,0 +1,67 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('agent2') + + +def test_zabbixagent_running_and_enabled(host): + zabbixagent = host.service("zabbix-agent2") + # Find out why this is not working for linuxmint and opensuse + if host.system_info.distribution not in ['linuxmint', 'opensuse', 'ubuntu']: + assert zabbixagent.is_running + assert zabbixagent.is_enabled + + +def test_zabbix_agent_dot_conf(host): + if host.system_info.distribution in ['opensuse']: + passwd = host.file("/etc/zabbix/zabbix-agentd.conf") + else: + passwd = host.file("/etc/zabbix/zabbix_agent2.conf") + assert passwd.user == "root" + assert passwd.group == "root" + assert passwd.mode == 0o644 + + assert passwd.contains("Server=192.168.3.33") + assert passwd.contains("ServerActive=192.168.3.33") + assert passwd.contains("DebugLevel=3") + assert passwd.contains("TLSAccept=psk") + assert passwd.contains("TLSPSKIdentity=my_Identity") + assert passwd.contains("TLSPSKFile=/data/certs/zabbix.psk") + assert passwd.contains("Plugins.SystemRun.LogRemoteCommands=0") + + +def test_zabbix_agent_psk(host): + psk_file = host.file("/data/certs/zabbix.psk") + assert psk_file.user == "zabbix" + assert psk_file.group == "zabbix" + assert psk_file.mode == 0o400 + assert psk_file.contains("97defd6bd126d5ba7fa5f296595f82eac905d5eda270207a580ab7c0cb9e8eab") + + +def test_zabbix_include_dir(host): + zabbixagent = host.file("/etc/zabbix/zabbix_agent2.d") + assert zabbixagent.is_directory + assert zabbixagent.user == "root" + assert zabbixagent.group == "zabbix" + + +def test_socket(host): + # Find out why this is not working for linuxmint and opensus + if host.system_info.distribution not in ['linuxmint', 'opensuse']: + assert host.socket("tcp://0.0.0.0:10050").is_listening + + +@pytest.mark.parametrize("zabbix_packages", [ + ("zabbix-agent2"), +]) +def test_zabbix_package(host, zabbix_packages): + zabbixagent = host.package(zabbix_packages) + assert zabbixagent.is_installed + + if host.system_info.distribution == 'debian': + assert zabbixagent.version.startswith("1:5.2") + if host.system_info.distribution == 'centos': + assert zabbixagent.version.startswith("5.2") diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_docker.py b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_docker.py new file mode 100644 index 00000000..a3b96d0b --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_agent/tests/test_docker.py @@ -0,0 +1,22 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('docker') + + +def test_docker_running(host): + zabbixagent = host.docker("zabbix-agent") + zabbixagent.is_running + + +def test_zabbix_include_dir(host): + zabbixagent = host.file("/etc/zabbix/zabbix_agentd.d") + assert zabbixagent.is_directory + assert zabbixagent.user == "root" + assert zabbixagent.group == "zabbix" + + +def test_socket(host): + assert host.socket("tcp://0.0.0.0:10050").is_listening diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/converge.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/converge.yml new file mode 100644 index 00000000..ae76d6ee --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/converge.yml @@ -0,0 +1,6 @@ +--- +- name: Converge + hosts: all + roles: + - role: zabbix_javagateway + javagateway_pidfile: /tmp/zabbix_java.pid diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml new file mode 100644 index 00000000..6d5c97c0 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml @@ -0,0 +1,27 @@ +--- +driver: + name: docker + +platforms: + - name: zabbix-javagateway-${MY_MOLECULE_CONTAINER:-centos} + image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"} + command: ${MY_MOLECULE_DOCKER_COMMAND:-""} + privileged: True + pre_build_image: True + networks: + - name: zabbix + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + +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 + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml new file mode 100644 index 00000000..9852d377 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml @@ -0,0 +1,57 @@ +--- +- name: Prepare + hosts: all + pre_tasks: + + - name: "Set short version name" + set_fact: + zabbix_python_prefix: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}" + + - name: "Installing packages on CentOS" + yum: + name: + - net-tools + - which + - sudo + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family == 'RedHat' + + - name: "Make sure the docs can be installed. (Debian)" + lineinfile: + path: /etc/dpkg/dpkg.cfg.d/excludes + state: absent + regexp: 'path-exclude=/usr/share/doc/*' + when: + - ansible_os_family != 'RedHat' + + # https://github.com/geerlingguy/ansible-role-java/issues/64 + - name: "Apt update" + shell: "apt-get update && mkdir -p /usr/share/man/man1" + args: + warn: False + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' + + - name: "Installing packages on NON-CentOS" + apt: + name: + - net-tools + - apt-utils + - procps + - "{{ zabbix_python_prefix }}-pip" + - gpg-agent + - "{{ zabbix_python_prefix }}-apt" + - sudo + - software-properties-common + - openjdk-11-jdk + update_cache: True + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/tests/test_default.py b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/tests/test_default.py new file mode 100644 index 00000000..57ff0e12 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_javagateway/tests/test_default.py @@ -0,0 +1,23 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_zabbix_running_and_enabled(host): + zabbix = host.service("zabbix-java-gateway") + assert zabbix.is_running + + +def test_zabbix_java_gateway_dot_conf(host): + zabbix_proxy_conf = host.file("/etc/zabbix/zabbix_java_gateway.conf") + assert zabbix_proxy_conf.user == "zabbix" + assert zabbix_proxy_conf.group == "zabbix" + assert zabbix_proxy_conf.mode == 0o644 + + assert zabbix_proxy_conf.contains("LISTEN_IP=0.0.0.0") + assert zabbix_proxy_conf.contains("LISTEN_PORT=10052") + assert zabbix_proxy_conf.contains("PID_FILE=/run/zabbix/zabbix_java_gateway.pid") + assert zabbix_proxy_conf.contains("START_POLLERS=5") diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/converge.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/converge.yml new file mode 100644 index 00000000..d5413e2a --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/converge.yml @@ -0,0 +1,4 @@ +--- +- hosts: all + roles: + - role: zabbix_proxy diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/destroy.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/destroy.yml new file mode 100644 index 00000000..1a487480 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/destroy.yml @@ -0,0 +1,25 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: False + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + vars: + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" + molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}" + tasks: + - name: Destroy molecule instance(s) + docker_container: + name: "{{ item.name }}" + state: absent + force_kill: "{{ item.force_kill | default(True) }}" + with_items: "{{ molecule_yml.platforms }}" + + - name: Destroy 3rd party instance(s) + docker_container: + name: '{{ item }}' + state: absent + force_kill: True + with_items: + - mysql-host + - postgresql-host diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml new file mode 100644 index 00000000..7fcb7015 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml @@ -0,0 +1,56 @@ +--- + +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:-""} + privileged: True + pre_build_image: True + networks: + - name: zabbix + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + groups: + - ${MY_MOLECULE_GROUP:-mysql} + +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: + mysql: + 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_mysql_login_host: mysql-host + zabbix_proxy_mysql_login_user: root + zabbix_proxy_mysql_login_password: changeme + zabbix_proxy_mysql_login_port: 3306 + postgresql: + zabbix_proxy_database: pgsql + zabbix_proxy_database_long: postgresql + zabbix_proxy_dbport: 5432 + zabbix_proxy_dbhost: postgresql-host + zabbix_proxy_dbhost_run_install: false + zabbix_proxy_pgsql_login_host: postgresql-host + zabbix_proxy_pgsql_login_user: postgres + zabbix_proxy_pgsql_login_password: changeme + zabbix_proxy_pgsql_login_port: 5432 + sqlite3: + 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/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml new file mode 100644 index 00000000..67b5aaa6 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml @@ -0,0 +1,129 @@ +--- +- name: Prepare + hosts: localhost + connection: local + pre_tasks: + + - name: "Create MySQL Container" + docker_container: + name: mysql-host + image: mysql:5.7 + state: started + recreate: yes + networks: + - name: zabbix + env: + MYSQL_ROOT_PASSWORD: changeme + no_log: true + with_items: "{{ molecule_yml.platforms }}" + when: + - '"mysql" in item.groups' + + - name: "Create postgresql Container" + docker_container: + name: postgresql-host + image: postgres + state: started + recreate: yes + networks: + - name: zabbix + env: + POSTGRES_PASSWORD: changeme + no_log: true + with_items: "{{ molecule_yml.platforms }}" + when: + - '"postgresql" in item.groups' + +- name: Prepare + hosts: all + tasks: + + - name: "Set short version name" + set_fact: + zabbix_python_prefix: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}" + + - name: "Create group for imaginary host" + add_host: + name: imaginary-host + groups: + - mysql + - postgresql + changed_when: False + + - name: "Installing packages on CentOS" + yum: + name: + - net-tools + - which + - sudo + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + 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: "Apt update" + shell: "apt-get update && echo exit 0 > /usr/sbin/policy-rc.d" + args: + warn: False + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' + + - name: "Installing packages on NON-CentOS" + apt: + name: + - net-tools + - apt-utils + - "{{ zabbix_python_prefix }}-pip" + - gpg-agent + - sudo + - doc-base + update_cache: True + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' + + - name: "Configure SUDO." + lineinfile: + dest: /etc/sudoers + line: "Defaults !requiretty" + state: present + + - name: "Make sure the docs can be installed. (RedHat)" + lineinfile: + dest: /etc/yum.conf + line: "tsflags=nodocs" + state: absent + when: + - ansible_os_family == 'RedHat' + + - name: "Make sure the docs can be installed. (Debian)" + lineinfile: + path: /etc/dpkg/dpkg.cfg.d/excludes + state: absent + 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/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py new file mode 100644 index 00000000..a0edb127 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py @@ -0,0 +1,62 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_zabbixproxy_running_and_enabled(host): + zabbix = host.service("zabbix-proxy") + if host.system_info.distribution == 'centos': + assert zabbix.is_enabled + assert zabbix.is_running + else: + assert zabbix.is_running + + +@pytest.mark.parametrize("proxy", [("zabbix-proxy-pgsql"), ("zabbix-proxy-mysql"), ("zabbix-proxy-sqlite3")]) +def test_zabbix_package(host, proxy): + ansible_data = host.ansible.get_variables() + zabbixhost = ansible_data['inventory_hostname'] + + zabbixhost = zabbixhost.replace("-centos", "") + zabbixhost = zabbixhost.replace("-debian", "") + zabbixhost = zabbixhost.replace("-ubuntu", "") + + if zabbixhost == proxy: + if host.system_info.distribution in ['debian', 'ubuntu']: + zabbix_proxy = host.package(proxy) + assert zabbix_proxy.version.startswith("1:5.2") + elif host.system_info.distribution == 'centos': + zabbix_proxy = host.package(proxy) + assert zabbix_proxy.version.startswith("5.2") + assert zabbix_proxy.is_installed + + +def test_zabbix_proxy_dot_conf(host): + zabbix_proxy_conf = host.file("/etc/zabbix/zabbix_proxy.conf") + assert zabbix_proxy_conf.user == "zabbix" + assert zabbix_proxy_conf.group == "zabbix" + assert zabbix_proxy_conf.mode == 0o644 + + assert zabbix_proxy_conf.contains("ListenPort=10051") + assert zabbix_proxy_conf.contains("DebugLevel=3") + + +def test_zabbix_include_dir(host): + zabbix_include_dir = host.file("/etc/zabbix/zabbix_proxy.conf.d") + 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 not zabbix_logfile.contains('Access denied for user') + assert not zabbix_logfile.contains('database is down: reconnecting') + assert zabbix_logfile.contains('current database version') + assert zabbix_logfile.contains(r"proxy #0 started \[main process\]") diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/converge.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/converge.yml new file mode 100644 index 00000000..e4ce78fa --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/converge.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + become: True + roles: + - role: zabbix_server diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/destroy.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/destroy.yml new file mode 100644 index 00000000..1a487480 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/destroy.yml @@ -0,0 +1,25 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: False + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + vars: + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" + molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}" + tasks: + - name: Destroy molecule instance(s) + docker_container: + name: "{{ item.name }}" + state: absent + force_kill: "{{ item.force_kill | default(True) }}" + with_items: "{{ molecule_yml.platforms }}" + + - name: Destroy 3rd party instance(s) + docker_container: + name: '{{ item }}' + state: absent + force_kill: True + with_items: + - mysql-host + - postgresql-host diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml new file mode 100644 index 00000000..b5ab577d --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml @@ -0,0 +1,52 @@ +--- + +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:-""} + privileged: True + pre_build_image: True + networks: + - name: zabbix + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + groups: + - ${MY_MOLECULE_GROUP:-mysql} + +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: + 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 + 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: + zabbix_server_database: pgsql + zabbix_server_database_long: postgresql + zabbix_server_dbport: 5432 + zabbix_server_dbhost: postgresql-host + zabbix_server_dbhost_run_install: false + zabbix_server_pgsql_login_host: postgresql-host + zabbix_server_pgsql_login_user: postgres + zabbix_server_pgsql_login_password: changeme + zabbix_server_pgsql_login_port: 5432 + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml new file mode 100644 index 00000000..071cdd1f --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml @@ -0,0 +1,116 @@ +--- +- name: Prepare + hosts: localhost + connection: local + pre_tasks: + + - name: "Create MySQL Container" + docker_container: + name: mysql-host + image: mysql:5.7 + state: started + recreate: yes + networks: + - name: zabbix + env: + MYSQL_ROOT_PASSWORD: changeme + no_log: true + with_items: "{{ molecule_yml.platforms }}" + when: + - '"mysql" in item.groups' + + - name: "Create postgresql Container" + docker_container: + name: postgresql-host + image: postgres + state: started + recreate: yes + networks: + - name: zabbix + env: + POSTGRES_PASSWORD: changeme + no_log: true + with_items: "{{ molecule_yml.platforms }}" + when: + - '"postgresql" in item.groups' + +- name: Prepare + hosts: all + tasks: + + - name: "Create group for imaginary host" + add_host: + name: imaginary-host + groups: + - mysql + - postgresql + changed_when: False + + - name: "Installing packages on CentOS" + yum: + name: + - net-tools + - which + - sudo + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + 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: "Apt update" + shell: "apt-get update && echo exit 0 > /usr/sbin/policy-rc.d" + args: + warn: False + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' + + - name: "Installing packages on NON-CentOS" + apt: + name: + - net-tools + - apt-utils + - python3-pip + - gpg-agent + - sudo + update_cache: True + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' + + - name: "Configure SUDO." + lineinfile: + dest: /etc/sudoers + line: "Defaults !requiretty" + state: present + + - name: "Make sure the docs are installed." + lineinfile: + dest: /etc/yum.conf + line: "tsflags=nodocs" + state: absent + 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/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py new file mode 100644 index 00000000..0c45ad78 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py @@ -0,0 +1,62 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_zabbiserver_running_and_enabled(host): + zabbix = host.service("zabbix-server") + if host.system_info.distribution == 'centos': + assert zabbix.is_enabled + assert zabbix.is_running + else: + assert zabbix.is_running + + +@pytest.mark.parametrize("server", [("zabbix-server-pgsql"), ("zabbix-server-mysql")]) +def test_zabbix_package(host, server): + ansible_data = host.ansible.get_variables() + zabbixhost = ansible_data['inventory_hostname'] + + zabbixhost = zabbixhost.replace("-centos", "") + zabbixhost = zabbixhost.replace("-debian", "") + zabbixhost = zabbixhost.replace("-ubuntu", "") + + if zabbixhost == server: + if host.system_info.distribution in ['debian', 'ubuntu']: + zabbix_server = host.package(server) + assert zabbix_server.version.startswith("1:5.2") + elif host.system_info.distribution == 'centos': + zabbix_server = host.package(server) + assert zabbix_server.version.startswith("5.2") + assert zabbix_server.is_installed + + +def test_zabbix_server_dot_conf(host): + zabbix_server_conf = host.file("/etc/zabbix/zabbix_server.conf") + assert zabbix_server_conf.user == "zabbix" + assert zabbix_server_conf.group == "zabbix" + assert zabbix_server_conf.mode == 0o640 + + assert zabbix_server_conf.contains("ListenPort=10051") + assert zabbix_server_conf.contains("DebugLevel=3") + + +def test_zabbix_include_dir(host): + zabbix_include_dir = host.file("/etc/zabbix/zabbix_server.conf.d") + 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 not zabbix_logfile.contains('Access denied for user') + assert not zabbix_logfile.contains('database is down: reconnecting') + assert zabbix_logfile.contains('current database version') + assert zabbix_logfile.contains(r"server #0 started \[main process\]") diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/converge.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/converge.yml new file mode 100644 index 00000000..bd70be66 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: zabbix_web diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/destroy.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/destroy.yml new file mode 100644 index 00000000..1a487480 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/destroy.yml @@ -0,0 +1,25 @@ +--- +- name: Destroy + hosts: localhost + connection: local + gather_facts: False + no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}" + vars: + molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}" + molecule_yml: "{{ lookup('file', molecule_file) | from_yaml }}" + tasks: + - name: Destroy molecule instance(s) + docker_container: + name: "{{ item.name }}" + state: absent + force_kill: "{{ item.force_kill | default(True) }}" + with_items: "{{ molecule_yml.platforms }}" + + - name: Destroy 3rd party instance(s) + docker_container: + name: '{{ item }}' + state: absent + force_kill: True + with_items: + - mysql-host + - postgresql-host diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml new file mode 100644 index 00000000..74381e6d --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml @@ -0,0 +1,96 @@ +--- +dependency: + name: galaxy + enabled: true + options: + ignore-certs: True + ignore-errors: True + role-file: molecule/zabbix_web/requirements.yml + +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:-""} + privileged: True + pre_build_image: True + networks: + - name: zabbix + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + groups: + - ${MY_MOLECULE_GROUP:-mysql} + +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: + 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 + 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: + zabbix_server_database: pgsql + zabbix_server_database_long: postgresql + zabbix_server_dbport: 5432 + zabbix_server_dbhost: postgresql-host + zabbix_server_dbhost_run_install: false + zabbix_server_pgsql_login_host: postgresql-host + 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 + php_default_version_debian: 7.4 + zabbix_php_fpm_conf_listen: False + zabbix_url: zabbix-web-pgsql-debian + zabbix_websrv_servername: zabbix-web-pgsql-debian + zabbix-web-mysql-debian: + zabbix_websrv: apache + php_default_version_debian: 7.4 + zabbix_php_fpm_conf_listen: False + zabbix_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_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_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_url: zabbix-web-mysql-ubuntu18 + zabbix_websrv_servername: zabbix-web-mysql-ubuntu18 + zabbix-web-pgsql-ubuntu20: + zabbix_php_fpm_conf_listen: False + zabbix_websrv: apache + zabbix_url: zabbix-web-pgsql-ubuntu20 + zabbix_websrv_servername: zabbix-web-pgsql-ubuntu20 + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml new file mode 100644 index 00000000..afb6d5a3 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml @@ -0,0 +1,146 @@ +--- +- name: Prepare + hosts: localhost + connection: local + pre_tasks: + + - name: "Create MySQL Container" + docker_container: + name: mysql-host + image: mysql:5.7 + state: started + recreate: yes + networks: + - name: zabbix + env: + MYSQL_ROOT_PASSWORD: changeme + no_log: true + with_items: "{{ molecule_yml.platforms }}" + when: + - '"mysql" in item.groups' + + - name: "Create postgresql Container" + docker_container: + name: postgresql-host + image: postgres + state: started + recreate: yes + networks: + - name: zabbix + env: + POSTGRES_PASSWORD: changeme + no_log: true + with_items: "{{ molecule_yml.platforms }}" + when: + - '"postgresql" in item.groups' + +- name: Prepare + hosts: all + pre_tasks: + + - name: "Create group for imaginary host" + add_host: + name: imaginary-host + groups: + - mysql + - postgresql + changed_when: False + + - name: "Installing packages on CentOS" + yum: + name: + - net-tools + - which + - curl + - sudo + - "{{ 'python3-libselinux' if ansible_distribution_major_version == '8' else 'libselinux-python' }}" + - "{{ 'python3-pip' if ansible_distribution_major_version == '8' else 'python-pip' }}" + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family == 'RedHat' + + - name: "Installing packages (CentOS7)" + yum: + name: + - centos-release-scl + state: present + register: installation_dependencies + when: + - ansible_os_family == 'RedHat' + - ansible_distribution_major_version == '7' + + - 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: "Installing packages on NON-CentOS" + apt: + name: + - net-tools + - curl + - apt-utils + - apt-transport-https + - ca-certificates + - python-apt + - gnupg2 + - "{{ 'python3-pip' if ansible_distribution == 'Ubuntu' else 'python-pip' }}" + - "{{ 'gnupg-agent' if ansible_distribution_major_version in ['7', '8'] else 'gpg-agent' }}" + - sudo + - vim + update_cache: True + state: present + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - ansible_os_family != 'RedHat' + + - name: "Configure SUDO." + lineinfile: + dest: /etc/sudoers + line: "Defaults !requiretty" + state: present + + - name: "Make sure the docs are installed." + lineinfile: + dest: /etc/yum.conf + line: "tsflags=nodocs" + state: absent + when: + - ansible_os_family == 'RedHat' + + - name: PyMySQL + pip: + name: PyMySQL + register: installation_dependencies + until: installation_dependencies is succeeded + when: + - inventory_hostname in groups['mysql'] + + roles: + - role: geerlingguy.apache + when: + - zabbix_websrv == "apache" + - role: geerlingguy.nginx + when: + - zabbix_websrv == "nginx" + - role: wdijkerman.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: + path: '{{ item }}' + state: absent + with_items: + - /var/www/html/index.html diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/requirements.yml b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/requirements.yml new file mode 100644 index 00000000..16ccb519 --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/requirements.yml @@ -0,0 +1,5 @@ +--- +- src: geerlingguy.apache +- src: geerlingguy.nginx +- name: wdijkerman.php + src: https://github.com/dj-wasabi/ansible-role-php.git diff --git a/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py new file mode 100644 index 00000000..e67e2a0e --- /dev/null +++ b/collections-debian-merged/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py @@ -0,0 +1,58 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).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", "") + + if host == server: + if host.system_info.distribution in ['debian', 'ubuntu']: + zabbix_web = host.package(debian) + assert zabbix_web.version.startswith("1:5.2") + elif host.system_info.distribution == 'centos': + zabbix_web = host.package(redhat) + assert zabbix_web.version.startswith("5.2") + assert zabbix_web.is_installed + + +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']) + + if host.system_info.distribution in ['debian', 'ubuntu']: + assert zabbix_web.user == "www-data" + assert zabbix_web.group == "www-data" + elif host.system_info.distribution == 'centos': + if zabbix_websrv == 'apache': + assert zabbix_web.user == "apache" + assert zabbix_web.group == "apache" + elif zabbix_websrv == 'nginx': + assert zabbix_web.user == "nginx" + assert zabbix_web.group == "nginx" + assert zabbix_web.mode == 0o640 + + +def test_zabbix_api(host): + my_host = host.ansible.get_variables() + zabbix_url = str(my_host['zabbix_url']) + hostname = 'http://' + zabbix_url + '/api_jsonrpc.php' + post_data = '{"jsonrpc": "2.0", "method": "user.login", "params": { "user": "Admin", "password": "zabbix" }, "id": 1, "auth": null}' + headers = 'Content-Type: application/json-rpc' + command = "curl -XPOST -H '" + str(headers) + "' -d '" + str(post_data) + "' '" + hostname + "'" + + cmd = host.run(command) + assert '"jsonrpc":"2.0","result":"' in cmd.stdout -- cgit v1.2.3