Init: mediaserver

This commit is contained in:
2023-02-08 12:13:28 +01:00
parent 848bc9739c
commit f7c23d4ba9
31914 changed files with 6175775 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
# Install CI dependencies for the Zabbix Roles
ansible==4.6.0
ansible-compat==0.5.0
ansible-core==2.11.5
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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: zabbix_agent

View File

@@ -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

View File

@@ -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")

View File

@@ -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

View File

@@ -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.2")
else:
assert zabbix_agent_package.version.startswith("1:6.0")
if host.system_info.distribution == "centos":
assert zabbix_agent_package.version.startswith("6.2")

View File

@@ -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"
)

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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.2")
else:
assert zabbix_agent_package.version.startswith("1:6.0")
if host.system_info.distribution == "centos":
assert zabbix_agent_package.version.startswith("6.2")

View File

@@ -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")

View File

@@ -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"
)

View File

@@ -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

View File

@@ -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")

View File

@@ -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

View File

@@ -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.2")
else:
assert zabbix_agent_package.version.startswith("1:6.0")
if host.system_info.distribution == "centos":
assert zabbix_agent_package.version.startswith("6.2")

View File

@@ -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")

View File

@@ -0,0 +1,9 @@
---
scenario:
name: autopsk
provisioner:
name: ansible
inventory:
group_vars:
all:
zabbix_agent_tlspsk_auto: True

View File

@@ -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

View File

@@ -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.2")
else:
assert zabbix_agent_package.version.startswith("1:6.0")
if host.system_info.distribution == "centos":
assert zabbix_agent_package.version.startswith("6.2")

View File

@@ -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")

View File

@@ -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

View File

@@ -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.2")
else:
assert zabbix_agent_package.version.startswith("1:6.0")
if host.system_info.distribution == "centos":
assert zabbix_agent_package.version.startswith("6.2")

View File

@@ -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")

View File

@@ -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"
)

View File

@@ -0,0 +1,6 @@
---
- name: Converge
hosts: all
roles:
- role: zabbix_javagateway
javagateway_pidfile: /tmp/zabbix_java.pid

View File

@@ -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

View File

@@ -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'

View File

@@ -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")

View File

@@ -0,0 +1,4 @@
---
- hosts: all
roles:
- role: zabbix_proxy

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,129 @@
---
- 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: "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']

View File

@@ -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.2")
elif host.system_info.distribution == "centos":
assert zabbix_proxy.version.startswith("6.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\]")

View File

@@ -0,0 +1,5 @@
---
- hosts: all
become: true
roles:
- role: zabbix_server

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,116 @@
---
- 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: "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']

View File

@@ -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.2")
elif host.system_info.distribution == "centos":
assert zabbix_server.version.startswith("6.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\]")

View File

@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: zabbix_web

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,4 @@
---
- src: geerlingguy.apache
- src: geerlingguy.nginx
- src: geerlingguy.php

View File

@@ -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.2")
elif host.system_info.distribution == "centos":
zabbix_web = host.package(redhat)
assert zabbix_web.version.startswith("6.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_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": { "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