Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy update #3

Merged
merged 18 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 30 additions & 34 deletions .github/workflows/proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,32 @@ jobs:
strategy:
fail-fast: false
matrix:
molecule_distro:
- container: mysql-centos
image: geerlingguy/docker-rockylinux8-ansible:latest
group: mysql
- container: pgsql-centos
image: geerlingguy/docker-rockylinux8-ansible:latest
group: postgresql
- container: sqlite-centos
image: geerlingguy/docker-rockylinux8-ansible:latest
group: sqlite3
- container: mysql-ubuntu
image: geerlingguy/docker-ubuntu2004-ansible
group: mysql
- container: pgsql-ubuntu
image: geerlingguy/docker-ubuntu2004-ansible
group: postgresql
command: /sbin/init
- container: sqlite-ubuntu
image: geerlingguy/docker-ubuntu2004-ansible
group: sqlite3
command: /sbin/init
- container: mysql-debian
image: geerlingguy/docker-debian11-ansible
group: mysql
- container: pgsql-debian
image: geerlingguy/docker-debian11-ansible
group: postgresql
- container: sqlite-debian
image: geerlingguy/docker-debian11-ansible
group: sqlite3
container:
- rockylinux9
- rockylinux8
- centos7
- ubuntu2204
- ubuntu2004
- ubuntu1804
- debian11
- debian10
collection_role:
- zabbix_proxy
database:
- mysql
- pgsql
- sqlite3
version:
- v62
- v60
- v50
include:
- interpreter: python3
- interpreter: python
container: centos7
exclude:
- container: rockylinux9
version: v50
steps:
- name: Check out code
uses: actions/checkout@v1
Expand All @@ -75,8 +69,10 @@ jobs:

- name: Run role tests
run: >-
MY_MOLECULE_CONTAINER=${{ matrix.molecule_distro.container }}
MY_MOLECULE_IMAGE=${{ matrix.molecule_distro.image }}
MY_MOLECULE_GROUP=${{ matrix.molecule_distro.group }}
MY_MOLECULE_DOCKER_COMMAND=${{ matrix.molecule_distro.command }}
MY_MOLECULE_CONTAINER=${{ matrix.container }}
MY_MOLECULE_IMAGE=${{ matrix.container }}
MY_MOLECULE_VERSION=${{ matrix.version }}
MY_MOLECULE_DATABASE=${{ matrix.database }}
MY_MOLECULE_INTERPRETER=${{ matrix.interpreter }}
MY_MOLECULE_DOCKER_COMMAND=${{ matrix.command }}
molecule test -s ${{ matrix.collection_role }}
30 changes: 19 additions & 11 deletions molecule/zabbix_proxy/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---

driver:
name: docker
platforms:
- name: zabbix-proxy-${MY_MOLECULE_CONTAINER:-mysql-centos}
image: ${MY_MOLECULE_IMAGE:-"geerlingguy/docker-centos8-ansible"}
command: ${MY_MOLECULE_DOCKER_COMMAND:-""}
- name: zabbix-proxy-${MY_MOLECULE_CONTAINER:-centos}
image: geerlingguy/docker-${MY_MOLECULE_IMAGE:-"centos8"}-ansible:latest
privileged: true
pre_build_image: true
command: ${MOLECULE_DOCKER_COMMAND:-""}
networks:
- name: zabbix
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
groups:
- ${MY_MOLECULE_GROUP:-mysql}
- ${MY_MOLECULE_DATABASE:-mysql}
- ${MY_MOLECULE_VERSION:-v62}

provisioner:
name: ansible
Expand All @@ -24,22 +24,31 @@ provisioner:
ANSIBLE_ROLES_PATH: $HOME/.ansible/collections/ansible_collections/community/zabbix/roles
inventory:
group_vars:
all:
python3:
ansible_python_interpreter: /usr/bin/python3
python:
ansible_python_interpreter: /usr/bin/python
v62:
zabbix_proxy_version: 6.2
v60:
zabbix_proxy_version: 6.0
v50:
zabbix_proxy_version: 5.0
mysql:
zabbix_proxy_dbname: zabbix
zabbix_proxy_dbuser: zabbix-dbuser
zabbix_proxy_database: mysql
zabbix_proxy_database_long: mysql
zabbix_proxy_dbport: 3306
zabbix_proxy_dbhost: mysql-host
zabbix_proxy_dbhost_run_install: false
zabbix_proxy_privileged_host: '%'
zabbix_proxy_privileged_host: "%"
zabbix_proxy_mysql_login_host: mysql-host
zabbix_proxy_mysql_login_user: root
zabbix_proxy_mysql_login_password: changeme
zabbix_proxy_mysql_login_port: 3306
postgresql:
zabbix_proxy_install_database_client: false
pgsql:
zabbix_proxy_database: pgsql
zabbix_proxy_database_long: postgresql
zabbix_proxy_dbport: 5432
zabbix_proxy_dbhost: postgresql-host
zabbix_proxy_dbhost_run_install: false
Expand All @@ -51,7 +60,6 @@ provisioner:
zabbix_proxy_database: sqlite3
zabbix_proxy_database_long: sqlite3
zabbix_proxy_dbname: /path/to/sqlite3.db

verifier:
name: testinfra
lint:
Expand Down
62 changes: 47 additions & 15 deletions molecule/zabbix_proxy/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
hosts: localhost
connection: local
pre_tasks:

- name: "Create MySQL Container"
docker_container:
name: mysql-host
Expand Down Expand Up @@ -32,12 +31,11 @@
no_log: true
with_items: "{{ molecule_yml.platforms }}"
when:
- '"postgresql" in item.groups'
- '"pgsql" in item.groups'

- name: Prepare
hosts: all
tasks:

- name: "Set short version name"
set_fact:
zabbix_python_prefix: "python{% if ansible_python_version is version('3', '>=') %}3{% endif %}"
Expand All @@ -62,17 +60,6 @@
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
Expand Down Expand Up @@ -121,7 +108,7 @@
lineinfile:
path: /etc/dpkg/dpkg.cfg.d/excludes
state: absent
regexp: 'path-exclude=/usr/share/doc/*'
regexp: "path-exclude=/usr/share/doc/*"
when:
- ansible_os_family != 'RedHat'

Expand All @@ -132,3 +119,48 @@
until: installation_dependencies is succeeded
when:
- inventory_hostname in groups['mysql']

- name: Install MariaDB (RHEL)
block:
- name: Add MariaDB Repo
ansible.builtin.yum_repository:
name: mariadb
description: MariaDB 10.8 CentOS repository list
file: mariadb
baseurl: "https://mirror.rackspace.com/mariadb/yum/10.8/centos{{ ansible_distribution_major_version }}-amd64"
gpgcheck: no
when: ansible_distribution_major_version <= '8'

- name: Install MariaDB Client
yum:
name:
- "{{ 'mariadb' if ansible_distribution_major_version >= '8' else 'MariaDB-client' }}"
- "{{ 'python3-PyMySQL' if ansible_distribution_major_version >= '8' else 'MySQL-python' }}"
when:
- ansible_os_family == 'RedHat'
- zabbix_proxy_database == 'mysql'

- name: Install MariaDB (Debian)
block:
- name: Add an Apt signing key, uses whichever key is at the URL
ansible.builtin.apt_key:
url: https://mariadb.org/mariadb_release_signing_key.asc
state: present

- name: Add specified repository into sources list
ansible.builtin.apt_repository:
repo: "deb https://mirror.rackspace.com/mariadb/repo/10.8/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} main"
state: present
validate_certs: false

- name: Install MariaDB Client
ansible.builtin.apt:
name:
- mariadb-client
- "{{ zabbix_python_prefix }}-mysqldb"
state: present
update_cache: true
allow_unauthenticated: true
when:
- ansible_os_family == 'Debian'
- zabbix_proxy_database == 'mysql'
34 changes: 27 additions & 7 deletions molecule/zabbix_proxy/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,19 @@ def test_zabbix_package(host, proxy):


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"
found = False
for file_name in [
"/etc/zabbix/zabbix_proxy.conf",
"/etc/zabbix_proxy.conf",
]:
if host.file(file_name).exists:
found = True
break

assert found
zabbix_proxy_conf = host.file(file_name)
assert zabbix_proxy_conf.user in ["zabbix", "zabbixsrv"]
assert zabbix_proxy_conf.group in ["zabbix", "zabbixsrv"]
assert zabbix_proxy_conf.mode == 0o644

assert zabbix_proxy_conf.contains("ListenPort=10051")
Expand All @@ -50,14 +60,24 @@ def test_zabbix_proxy_dot_conf(host):
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.user in ["zabbix", "zabbixsrv"]
assert zabbix_include_dir.group in ["zabbix", "zabbixsrv"]
# assert zabbix_include_dir.mode == 0o644


def test_zabbix_proxy_logfile(host):
zabbix_logfile = host.file("/var/log/zabbix/zabbix_proxy.log")

found = False
for file_name in [
"/var/log/zabbix/zabbix_proxy.log",
"/var/log/zabbixsrv/zabbix_proxy.log",
]:
if host.file(file_name).exists:
found = True
break

assert found

zabbix_logfile = host.file(file_name)
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")
Expand Down
Loading