Skip to content

Commit

Permalink
Make the role compatible with Alpine linux
Browse files Browse the repository at this point in the history
  • Loading branch information
fauust committed Sep 26, 2023
1 parent 40297fc commit 6962c94
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- fedora-38
- almalinux-9
- rockylinux-8
- alpine-3.18
steps:
- uses: actions/checkout@v4
- name: Install requirements
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
- almalinux-9
- rockylinux-8
- rockylinux-9
- alpine-3.17
- alpine-3.18
steps:
- uses: actions/checkout@v4
- name: Install requirements
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Cluster](https://github.com/fauust/ansible-role-mariadb/actions/workflows/test_cluster.yml/badge.svg)](https://github.com/fauust/ansible-role-mariadb/actions/workflows/test_cluster.yml)
[![Cluster MDBF](https://github.com/fauust/ansible-role-mariadb/actions/workflows/test_cluster_mdbf.yml/badge.svg)](https://github.com/fauust/ansible-role-mariadb/actions/workflows/test_cluster_mdbf.yml)

Install and configure MariaDB Server on Linux (Debian or RHEL based).
Install and configure MariaDB Server on Linux (Debian, RHEL or Alpine linux based).

Optionally, this role also permits one to:

Expand Down Expand Up @@ -128,6 +128,8 @@ deployments and you are encouraged to use your own values.
[`vars`](./vars).

```yaml
mariadb_user: "default value depends on OS"
mariadb_package: "default value depends on OS"
mariadb_config_file: "default value depends on OS"
mariadb_data_dir: "default value depends on OS"
mariadb_port: 3306
Expand Down
3 changes: 3 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
when:
- mariadb_can_restart
- not ansible_check_mode

- name: Setup MariaDB
ansible.builtin.command: /etc/init.d/mariadb setup
14 changes: 6 additions & 8 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ galaxy_info:
platforms:
- name: Debian
versions:
- buster
- bullseye
- sid
- all
- name: Ubuntu
versions:
- bionic
- focal
- jammy
- all
- name: Fedora
versions:
- all
- name: EL
versions:
- 8
- 9
- all
- name: Alpine
versions:
- all
galaxy_tags:
- mariadb
- mysql
20 changes: 12 additions & 8 deletions molecule/cluster/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
hosts: all

tasks:
- name: Get mariadb service status
ansible.builtin.systemd:
name: "mariadb"
register: mariadb_service
- name: Make sure that service is started
ansible.builtin.service:
name: mariadb
state: started
register: status
failed_when: status.changed

- name: Check that mariadb service is active
ansible.builtin.assert:
that:
- mariadb_service.status.ActiveState == 'active'
- name: Make sure that service is enabled
ansible.builtin.service:
name: mariadb
state: enabled
register: status
failed_when: status.changed

- name: Verify replication
hosts: replica
Expand Down
1 change: 1 addition & 0 deletions molecule/default/vars/Alpine.yml
38 changes: 23 additions & 15 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
paths:
- "vars"

- name: Gather package facts
ansible.builtin.package_facts:
manager: auto

- name: Verify Packages
- name: Verify pkg status
ansible.builtin.package:
name: "{{ mariadb_package }}"
state: present
check_mode: true
register: pkg_status

- name: Check that {{ mariadb_package }} already installed
ansible.builtin.assert:
that: "'mariadb-server' in ansible_facts.packages|lower"
that: not pkg_status.changed
fail_msg: "{{ mariadb_package }} is not installed"

- name: Register {{ mariadb_config_file }}
ansible.builtin.stat:
Expand Down Expand Up @@ -58,15 +62,19 @@
- logdir.stat.pw_name == "{{ mariadb_user }}"
- logdir.stat.gr_name == "{{ mariadb_user }}"

- name: Get mariadb service status
ansible.builtin.systemd:
name: "mariadb"
register: mariadb_service

- name: Check that mariadb service is active
ansible.builtin.assert:
that:
- mariadb_service.status.ActiveState == 'active'
- name: Make sure that service is started
ansible.builtin.service:
name: mariadb
state: started
register: status
failed_when: status.changed

- name: Make sure that service is enabled
ansible.builtin.service:
name: mariadb
state: enabled
register: status
failed_when: status.changed

- name: Check that 127.0.0.1:3306 is listening
ansible.builtin.wait_for:
Expand Down
1 change: 1 addition & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
collections:
- name: community.general
- name: community.mysql
- name: containers.podman
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
ansible.builtin.import_tasks: setup_redhat.yml
when: ansible_os_family == "RedHat"

- name: Include task setup_alpine.yml
ansible.builtin.import_tasks: setup_alpine.yml
when: ansible_os_family == "Alpine"

- name: Include task configure.yml
ansible.builtin.import_tasks: configure.yml

Expand Down
34 changes: 34 additions & 0 deletions tasks/setup_alpine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Install packages (package)
ansible.builtin.package:
name:
- "{{ mariadb_package }}"
- mariadb-client
- py3-pymysql
state: present
notify: Setup MariaDB

- name: Check if mariadb command exists
ansible.builtin.stat:
path: /usr/bin/mariadb
register: mariadb_cmd

- name: Make sure that mariadb command exists
ansible.builtin.file:
src: /usr/bin/mysql
dest: /usr/bin/mariadb
owner: root
group: root
state: link
when: mariadb_cmd.stat.exists is false

- name: Ensure /run/mysqld
ansible.builtin.file:
path: /run/mysqld
state: directory
owner: mysql
group: mysql
mode: 0755

- name: Immediately setup MariaDB (necessary for configuration)
ansible.builtin.meta: flush_handlers
4 changes: 2 additions & 2 deletions tasks/setup_debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@
group: root
mode: "0644"

- name: Install packages
- name: Install packages (apt)
ansible.builtin.apt:
package:
- mariadb-server
- "{{ mariadb_package }}"
- python3-pymysql
state: present
update_cache: true
4 changes: 2 additions & 2 deletions tasks/setup_redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
mode: "0644"
when: mariadb_use_official_repo

- name: Install packages
- name: Install packages (dnf)
ansible.builtin.dnf:
name:
- mariadb-server
- "{{ mariadb_package }}"
- python3-PyMySQL
state: present

Expand Down
10 changes: 10 additions & 0 deletions vars/Alpine.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
mariadb_user: mysql
mariadb_package: mariadb
mariadb_config_file: "/etc/my.cnf"
mariadb_data_dir: "/var/lib/mysql"
mariadb_pid_file: "/run/mysqld/mariadb.pid"
mariadb_unix_socket: "/run/mysqld/mysqld.sock"
mariadb_log_dir: "/var/log/mariadb"
mariadb_log_error_file: "{{ mariadb_log_dir }}/error.log"
mariadb_cron_package_name: "cronie"
1 change: 1 addition & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
mariadb_user: mysql
mariadb_package: mariadb-server
mariadb_config_file: "/etc/mysql/mariadb.cnf"
mariadb_data_dir: "/var/lib/mysql"
mariadb_pid_file: "/run/mysqld/mysqld.pid"
Expand Down
1 change: 1 addition & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
mariadb_user: mysql
mariadb_package: mariadb-server
mariadb_config_file: "/etc/my.cnf.d/mariadb-server.cnf"
mariadb_data_dir: "/var/lib/mysql"
mariadb_pid_file: "/run/mysqld.pid"
Expand Down

0 comments on commit 6962c94

Please sign in to comment.