diff options
Diffstat (limited to 'ansible_collections/community/zabbix/molecule')
47 files changed, 1811 insertions, 0 deletions
diff --git a/ansible_collections/community/zabbix/molecule/requirements.txt b/ansible_collections/community/zabbix/molecule/requirements.txt new file mode 100644 index 000000000..bec205a0a --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/requirements.txt @@ -0,0 +1,11 @@ +# Install CI dependencies for the Zabbix Roles +ansible==7.0.0 +ansible-compat==0.5.0 +ansible-core==2.14.2 +docker==5.0.2 +molecule==3.5.1 +molecule-docker==1.0.2 +netaddr==0.8.0 +pytest-testinfra==6.1.0 +ipaddr==2.2.0 +ipaddress==1.0.23 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 new file mode 100644 index 000000000..a0222246f --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/molecule.yml @@ -0,0 +1,58 @@ +--- +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: + - agent + +provisioner: + name: ansible + lint: + name: ansible-lint + playbooks: + prepare: ../../common/playbooks/prepare.yml + converge: ../../common/playbooks/converge.yml + 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: + 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 + +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/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/converge.yml b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/converge.yml new file mode 100644 index 000000000..7ce55d49e --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: zabbix_agent 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 new file mode 100644 index 000000000..3ce015db6 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/playbooks/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 ['10','18', '20'] else 'iproute2' }}" + state: present + update_cache: true + 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/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/agent2_common/test_agent2.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/agent2_common/test_agent2.py new file mode 100644 index 000000000..f1b3b0534 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/agent2_common/test_agent2.py @@ -0,0 +1,12 @@ +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_zabbix_agent2_dot_conf(host, zabbix_agent_file): + assert zabbix_agent_file.contains("Plugins.SystemRun.LogRemoteCommands=0") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/autopsk/test_auto_psk.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/autopsk/test_auto_psk.py new file mode 100644 index 000000000..859f2a255 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/autopsk/test_auto_psk.py @@ -0,0 +1,24 @@ +import pytest +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("agent") + + +def test_zabbix_agent_dot_conf(host, zabbix_agent_conf): + assert zabbix_agent_conf.contains("TLSAccept=psk") + assert zabbix_agent_conf.contains( + f"TLSPSKIdentity={host.ansible.get_variables()['inventory_hostname']}" + ) + assert zabbix_agent_conf.contains("TLSPSKFile=/etc/zabbix/tls_psk_auto.secret") + + +def test_zabbix_agent_autopsk(host): + psk_file = host.file("/etc/zabbix/tls_psk_auto.secret") + assert psk_file.user == "zabbix" + assert psk_file.group == "zabbix" + assert psk_file.mode == 0o400 + assert psk_file.size == 64 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 new file mode 100644 index 000000000..96d4a1716 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/common/test_agent.py @@ -0,0 +1,49 @@ +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, zabbix_agent_service): + # Find out why this is not working for linuxmint and opensuse + if host.system_info.distribution not in ["linuxmint", "opensuse", "ubuntu"]: + assert zabbix_agent_service.is_running + assert zabbix_agent_service.is_enabled + + +def test_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.user == "root" + assert zabbix_agent_conf.group == "root" + assert zabbix_agent_conf.mode == 0o644 + + assert zabbix_agent_conf.contains("Server=192.168.3.33") + assert zabbix_agent_conf.contains("ServerActive=192.168.3.33") + assert zabbix_agent_conf.contains("DebugLevel=3") + + +def test_zabbix_include_dir(zabbix_agent_include_dir): + assert zabbix_agent_include_dir.is_directory + assert zabbix_agent_include_dir.user == "root" + assert zabbix_agent_include_dir.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 + + +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/common/tests/no_auto_psk/test_no_auto_psk.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/no_auto_psk/test_no_auto_psk.py new file mode 100644 index 000000000..6fbbbb226 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/no_auto_psk/test_no_auto_psk.py @@ -0,0 +1,24 @@ +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_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.contains("TLSAccept=psk") + assert zabbix_agent_conf.contains("TLSPSKIdentity=my_Identity") + assert zabbix_agent_conf.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" + ) diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/test_docker.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/test_docker.py new file mode 100644 index 000000000..e8fe39f39 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/common/tests/test_docker.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("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/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/molecule.yml new file mode 100644 index 000000000..76edc902e --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/molecule.yml @@ -0,0 +1,19 @@ +--- +scenario: + name: agent2 +provisioner: + name: ansible + inventory: + group_vars: + all: + 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
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/agent2_common/test_agent2.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/agent2_common/test_agent2.py new file mode 100644 index 000000000..f1b3b0534 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/agent2_common/test_agent2.py @@ -0,0 +1,12 @@ +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_zabbix_agent2_dot_conf(host, zabbix_agent_file): + assert zabbix_agent_file.contains("Plugins.SystemRun.LogRemoteCommands=0") 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 new file mode 100644 index 000000000..96d4a1716 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/common/test_agent.py @@ -0,0 +1,49 @@ +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, zabbix_agent_service): + # Find out why this is not working for linuxmint and opensuse + if host.system_info.distribution not in ["linuxmint", "opensuse", "ubuntu"]: + assert zabbix_agent_service.is_running + assert zabbix_agent_service.is_enabled + + +def test_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.user == "root" + assert zabbix_agent_conf.group == "root" + assert zabbix_agent_conf.mode == 0o644 + + assert zabbix_agent_conf.contains("Server=192.168.3.33") + assert zabbix_agent_conf.contains("ServerActive=192.168.3.33") + assert zabbix_agent_conf.contains("DebugLevel=3") + + +def test_zabbix_include_dir(zabbix_agent_include_dir): + assert zabbix_agent_include_dir.is_directory + assert zabbix_agent_include_dir.user == "root" + assert zabbix_agent_include_dir.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 + + +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/conftest.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/conftest.py new file mode 100644 index 000000000..5d7087ab2 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/conftest.py @@ -0,0 +1,33 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("agent") + + +@pytest.fixture +def zabbix_agent_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") + + return passwd + + +@pytest.fixture +def zabbix_agent_service(host): + return host.service("zabbix-agent2") + + +@pytest.fixture +def zabbix_agent_include_dir(host): + return host.file("/etc/zabbix/zabbix_agent2.d") + + +@pytest.fixture +def zabbix_agent_package(host): + return host.package("zabbix-agent2") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/no_auto_psk/test_no_auto_psk.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/no_auto_psk/test_no_auto_psk.py new file mode 100644 index 000000000..6fbbbb226 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2/tests/no_auto_psk/test_no_auto_psk.py @@ -0,0 +1,24 @@ +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_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.contains("TLSAccept=psk") + assert zabbix_agent_conf.contains("TLSPSKIdentity=my_Identity") + assert zabbix_agent_conf.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" + ) diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/molecule.yml new file mode 100644 index 000000000..a63909406 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/molecule.yml @@ -0,0 +1,17 @@ +--- +scenario: + name: agent2autopsk +provisioner: + name: ansible + inventory: + group_vars: + all: + zabbix_agent2: true + zabbix_agent2_tlsconnect: psk + zabbix_agent2_tlsaccept: psk + zabbix_agent2_tlspsk_auto: True + zabbix_agent2_plugins: + - name: SystemRun + options: + - parameter: LogRemoteCommands + value: 0
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/agent2_common/test_agent2.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/agent2_common/test_agent2.py new file mode 100644 index 000000000..f1b3b0534 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/agent2_common/test_agent2.py @@ -0,0 +1,12 @@ +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_zabbix_agent2_dot_conf(host, zabbix_agent_file): + assert zabbix_agent_file.contains("Plugins.SystemRun.LogRemoteCommands=0") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/autopsk/test_auto_psk.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/autopsk/test_auto_psk.py new file mode 100644 index 000000000..859f2a255 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/autopsk/test_auto_psk.py @@ -0,0 +1,24 @@ +import pytest +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("agent") + + +def test_zabbix_agent_dot_conf(host, zabbix_agent_conf): + assert zabbix_agent_conf.contains("TLSAccept=psk") + assert zabbix_agent_conf.contains( + f"TLSPSKIdentity={host.ansible.get_variables()['inventory_hostname']}" + ) + assert zabbix_agent_conf.contains("TLSPSKFile=/etc/zabbix/tls_psk_auto.secret") + + +def test_zabbix_agent_autopsk(host): + psk_file = host.file("/etc/zabbix/tls_psk_auto.secret") + assert psk_file.user == "zabbix" + assert psk_file.group == "zabbix" + assert psk_file.mode == 0o400 + assert psk_file.size == 64 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 new file mode 100644 index 000000000..96d4a1716 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/common/test_agent.py @@ -0,0 +1,49 @@ +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, zabbix_agent_service): + # Find out why this is not working for linuxmint and opensuse + if host.system_info.distribution not in ["linuxmint", "opensuse", "ubuntu"]: + assert zabbix_agent_service.is_running + assert zabbix_agent_service.is_enabled + + +def test_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.user == "root" + assert zabbix_agent_conf.group == "root" + assert zabbix_agent_conf.mode == 0o644 + + assert zabbix_agent_conf.contains("Server=192.168.3.33") + assert zabbix_agent_conf.contains("ServerActive=192.168.3.33") + assert zabbix_agent_conf.contains("DebugLevel=3") + + +def test_zabbix_include_dir(zabbix_agent_include_dir): + assert zabbix_agent_include_dir.is_directory + assert zabbix_agent_include_dir.user == "root" + assert zabbix_agent_include_dir.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 + + +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/conftest.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/conftest.py new file mode 100644 index 000000000..5d7087ab2 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/agent2autopsk/tests/conftest.py @@ -0,0 +1,33 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("agent") + + +@pytest.fixture +def zabbix_agent_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") + + return passwd + + +@pytest.fixture +def zabbix_agent_service(host): + return host.service("zabbix-agent2") + + +@pytest.fixture +def zabbix_agent_include_dir(host): + return host.file("/etc/zabbix/zabbix_agent2.d") + + +@pytest.fixture +def zabbix_agent_package(host): + return host.package("zabbix-agent2") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/molecule.yml new file mode 100644 index 000000000..a4bf295c1 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/molecule.yml @@ -0,0 +1,9 @@ +--- +scenario: + name: autopsk +provisioner: + name: ansible + inventory: + group_vars: + all: + zabbix_agent_tlspsk_auto: True
\ No newline at end of file diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/autopsk/test_auto_psk.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/autopsk/test_auto_psk.py new file mode 100644 index 000000000..859f2a255 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/autopsk/test_auto_psk.py @@ -0,0 +1,24 @@ +import pytest +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("agent") + + +def test_zabbix_agent_dot_conf(host, zabbix_agent_conf): + assert zabbix_agent_conf.contains("TLSAccept=psk") + assert zabbix_agent_conf.contains( + f"TLSPSKIdentity={host.ansible.get_variables()['inventory_hostname']}" + ) + assert zabbix_agent_conf.contains("TLSPSKFile=/etc/zabbix/tls_psk_auto.secret") + + +def test_zabbix_agent_autopsk(host): + psk_file = host.file("/etc/zabbix/tls_psk_auto.secret") + assert psk_file.user == "zabbix" + assert psk_file.group == "zabbix" + assert psk_file.mode == 0o400 + assert psk_file.size == 64 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 new file mode 100644 index 000000000..96d4a1716 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/common/test_agent.py @@ -0,0 +1,49 @@ +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, zabbix_agent_service): + # Find out why this is not working for linuxmint and opensuse + if host.system_info.distribution not in ["linuxmint", "opensuse", "ubuntu"]: + assert zabbix_agent_service.is_running + assert zabbix_agent_service.is_enabled + + +def test_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.user == "root" + assert zabbix_agent_conf.group == "root" + assert zabbix_agent_conf.mode == 0o644 + + assert zabbix_agent_conf.contains("Server=192.168.3.33") + assert zabbix_agent_conf.contains("ServerActive=192.168.3.33") + assert zabbix_agent_conf.contains("DebugLevel=3") + + +def test_zabbix_include_dir(zabbix_agent_include_dir): + assert zabbix_agent_include_dir.is_directory + assert zabbix_agent_include_dir.user == "root" + assert zabbix_agent_include_dir.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 + + +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/conftest.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/conftest.py new file mode 100644 index 000000000..1ddde968c --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/autopsk/tests/conftest.py @@ -0,0 +1,33 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("agent") + + +@pytest.fixture +def zabbix_agent_conf(host): + if host.system_info.distribution in ["opensuse"]: + conf_file = host.file("/etc/zabbix/zabbix-agentd.conf") + else: + conf_file = host.file("/etc/zabbix/zabbix_agentd.conf") + + return conf_file + + +@pytest.fixture +def zabbix_agent_service(host): + return host.service("zabbix-agent") + + +@pytest.fixture +def zabbix_agent_include_dir(host): + return host.file("/etc/zabbix/zabbix_agentd.d") + + +@pytest.fixture +def zabbix_agent_package(host): + return host.package("zabbix-agent") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/molecule.yml new file mode 100644 index 000000000..8f053f0da --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/molecule.yml @@ -0,0 +1,11 @@ +--- +scenario: + name: default +provisioner: + name: ansible + inventory: + group_vars: + all: + zabbix_agent_tlspskidentity: my_Identity + zabbix_agent_tlspskfile: /data/certs/zabbix.psk + zabbix_agent_tlspsk_secret: 97defd6bd126d5ba7fa5f296595f82eac905d5eda270207a580ab7c0cb9e8eab 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 new file mode 100644 index 000000000..96d4a1716 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/common/test_agent.py @@ -0,0 +1,49 @@ +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, zabbix_agent_service): + # Find out why this is not working for linuxmint and opensuse + if host.system_info.distribution not in ["linuxmint", "opensuse", "ubuntu"]: + assert zabbix_agent_service.is_running + assert zabbix_agent_service.is_enabled + + +def test_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.user == "root" + assert zabbix_agent_conf.group == "root" + assert zabbix_agent_conf.mode == 0o644 + + assert zabbix_agent_conf.contains("Server=192.168.3.33") + assert zabbix_agent_conf.contains("ServerActive=192.168.3.33") + assert zabbix_agent_conf.contains("DebugLevel=3") + + +def test_zabbix_include_dir(zabbix_agent_include_dir): + assert zabbix_agent_include_dir.is_directory + assert zabbix_agent_include_dir.user == "root" + assert zabbix_agent_include_dir.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 + + +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/conftest.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/conftest.py new file mode 100644 index 000000000..1ddde968c --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/conftest.py @@ -0,0 +1,33 @@ +import os +import pytest + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("agent") + + +@pytest.fixture +def zabbix_agent_conf(host): + if host.system_info.distribution in ["opensuse"]: + conf_file = host.file("/etc/zabbix/zabbix-agentd.conf") + else: + conf_file = host.file("/etc/zabbix/zabbix_agentd.conf") + + return conf_file + + +@pytest.fixture +def zabbix_agent_service(host): + return host.service("zabbix-agent") + + +@pytest.fixture +def zabbix_agent_include_dir(host): + return host.file("/etc/zabbix/zabbix_agentd.d") + + +@pytest.fixture +def zabbix_agent_package(host): + return host.package("zabbix-agent") diff --git a/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/no_auto_psk/test_no_auto_psk.py b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/no_auto_psk/test_no_auto_psk.py new file mode 100644 index 000000000..6fbbbb226 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_agent_tests/molecule/default/tests/no_auto_psk/test_no_auto_psk.py @@ -0,0 +1,24 @@ +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_zabbix_agent_dot_conf(zabbix_agent_conf): + assert zabbix_agent_conf.contains("TLSAccept=psk") + assert zabbix_agent_conf.contains("TLSPSKIdentity=my_Identity") + assert zabbix_agent_conf.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" + ) diff --git a/ansible_collections/community/zabbix/molecule/zabbix_javagateway/converge.yml b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/converge.yml new file mode 100644 index 000000000..ae76d6ee8 --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/molecule.yml new file mode 100644 index 000000000..f56745b9b --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml new file mode 100644 index 000000000..9d24c9f7e --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/prepare.yml @@ -0,0 +1,62 @@ +--- +- 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' + + - name: Check if warn parameter can be used for shell module + 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" + 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: + 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/ansible_collections/community/zabbix/molecule/zabbix_javagateway/tests/test_default.py b/ansible_collections/community/zabbix/molecule/zabbix_javagateway/tests/test_default.py new file mode 100644 index 000000000..57ff0e129 --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_proxy/converge.yml b/ansible_collections/community/zabbix/molecule/zabbix_proxy/converge.yml new file mode 100644 index 000000000..d5413e2a4 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_proxy/converge.yml @@ -0,0 +1,4 @@ +--- +- hosts: all + roles: + - role: zabbix_proxy diff --git a/ansible_collections/community/zabbix/molecule/zabbix_proxy/destroy.yml b/ansible_collections/community/zabbix/molecule/zabbix_proxy/destroy.yml new file mode 100644 index 000000000..54771a5a1 --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_proxy/molecule.yml new file mode 100644 index 000000000..21ab813c4 --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml new file mode 100644 index 000000000..0fc4ef320 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_proxy/prepare.yml @@ -0,0 +1,134 @@ +--- +- name: Prepare + hosts: localhost + connection: local + pre_tasks: + + - name: "Create MySQL Container" + docker_container: + name: mysql-host + image: mysql:8.0 + state: started + recreate: true + 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:13 + state: started + recreate: true + 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: Check if warn parameter can be used for shell module + 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" + 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: + 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/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py b/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py new file mode 100644 index 000000000..4ccbfeb4e --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_proxy/tests/test_default.py @@ -0,0 +1,64 @@ +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: + 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 + + +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/ansible_collections/community/zabbix/molecule/zabbix_server/converge.yml b/ansible_collections/community/zabbix/molecule/zabbix_server/converge.yml new file mode 100644 index 000000000..cff36c579 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_server/converge.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + become: true + roles: + - role: zabbix_server diff --git a/ansible_collections/community/zabbix/molecule/zabbix_server/destroy.yml b/ansible_collections/community/zabbix/molecule/zabbix_server/destroy.yml new file mode 100644 index 000000000..54771a5a1 --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_server/molecule.yml new file mode 100644 index 000000000..4fa0a8daa --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml b/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml new file mode 100644 index 000000000..51945c066 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_server/prepare.yml @@ -0,0 +1,121 @@ +--- +- name: Prepare + hosts: localhost + connection: local + pre_tasks: + + - name: "Create MySQL Container" + docker_container: + name: mysql-host + image: mysql:8.0 + state: started + recreate: true + 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:13 + state: started + recreate: true + 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: Check if warn parameter can be used for shell module + 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" + 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: + 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/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py b/ansible_collections/community/zabbix/molecule/zabbix_server/tests/test_default.py new file mode 100644 index 000000000..9a119d5ac --- /dev/null +++ b/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: + 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 + + +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/ansible_collections/community/zabbix/molecule/zabbix_web/converge.yml b/ansible_collections/community/zabbix/molecule/zabbix_web/converge.yml new file mode 100644 index 000000000..bd70be664 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/converge.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: zabbix_web diff --git a/ansible_collections/community/zabbix/molecule/zabbix_web/destroy.yml b/ansible_collections/community/zabbix/molecule/zabbix_web/destroy.yml new file mode 100644 index 000000000..54771a5a1 --- /dev/null +++ b/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/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml b/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml new file mode 100644 index 000000000..baffecc47 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/molecule.yml @@ -0,0 +1,95 @@ +--- +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 + 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 + 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 new file mode 100644 index 000000000..3c0c6db86 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/prepare.yml @@ -0,0 +1,150 @@ +--- +- name: Prepare + hosts: localhost + connection: local + pre_tasks: + - name: "Create MySQL Container" + docker_container: + name: mysql-host + image: mysql:8.0 + state: started + recreate: true + 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:13 + state: started + recreate: true + 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-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 + 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 MySQL 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 + - gnupg2 + - 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' }}" + 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'] + + - name: Enabeling PHP 7.4 + command: dnf module enable php:7.4 -y + when: + - ansible_os_family == 'RedHat' + - ansible_distribution_major_version == "8" + + roles: + - role: geerlingguy.apache + when: + - zabbix_websrv == "apache" + - role: geerlingguy.nginx + when: + - zabbix_websrv == "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: + path: "{{ item }}" + state: absent + with_items: + - /var/www/html/index.html diff --git a/ansible_collections/community/zabbix/molecule/zabbix_web/requirements.yml b/ansible_collections/community/zabbix/molecule/zabbix_web/requirements.yml new file mode 100644 index 000000000..e08ac4c1f --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/requirements.yml @@ -0,0 +1,4 @@ +--- +- src: geerlingguy.apache +- src: geerlingguy.nginx +- src: geerlingguy.php 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 new file mode 100644 index 000000000..a6f7527b0 --- /dev/null +++ b/ansible_collections/community/zabbix/molecule/zabbix_web/tests/test_default.py @@ -0,0 +1,70 @@ +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: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 + + +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_api_server_url = str(my_host["zabbix_api_server_url"]) + hostname = "http://" + zabbix_api_server_url + "/api_jsonrpc.php" + post_data = '{"jsonrpc": "2.0", "method": "user.login", "params": { "username": "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 |