commit 278dba2c028c4c577bfc5e2fa6c7ef3ddb894e9a Author: Ludovic Cartier Date: Wed Sep 24 12:21:22 2025 +0200 first commit - install and upgrade mariaDB on debian system through official mariaDB repo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f486be2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2025 ansible-roles + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..806def4 --- /dev/null +++ b/README.md @@ -0,0 +1,227 @@ +# MariaDB Ansible Role + +An Ansible role for installing and configuring MariaDB on Debian-based systems using the official MariaDB repositories. + +## Features + +- ✅ Official MariaDB repository setup +- ✅ Flexible version management (major and minor versions) +- ✅ Automatic upgrade capabilities +- ✅ Idempotent operations +- ✅ Support for MariaDB versions 10, 11, and 12 +- ✅ Proper service management during upgrades + +## Requirements + +- **Target OS**: Debian-based systems (Debian, Ubuntu) +- **Ansible**: >= 2.8 +- **Privileges**: sudo/root access required + +## Role Variables + +### Required Variables +None. The role works with sensible defaults. + +### Optional Variables + +| Variable | Default | Description | +|----------|---------|-------------| +| `mariadb_major_version` | `"12"` | Major version for repository setup (10, 11, or 12) | +| `mariadb_minor_version` | `undefined` | Minor version for specific version install (e.g., "8" for 11.8.x) | +| `mariadb_force_upgrade` | `false` | Force repository update and package upgrade | + +### Variable Details + +#### `mariadb_major_version` +- **Type**: String +- **Choices**: `"10"`, `"11"`, `"12"` +- **Purpose**: Determines which MariaDB repository to configure + +#### `mariadb_minor_version` +- **Type**: String (optional) +- **Format**: Just the minor number (e.g., `"8"` for version 11.8.x) +- **Purpose**: Installs specific minor version, gets latest patch automatically +- **Behavior**: When undefined, installs the latest available version + +#### `mariadb_force_upgrade` +- **Type**: Boolean +- **Purpose**: Forces repository reconfiguration and package upgrades +- **Use case**: Required when upgrading between major versions + +## Dependencies + +None. + +## Example Playbooks + +### Basic Installation (Latest MariaDB 12) + +```yaml +- hosts: servers + roles: + - mariadb +``` + +### Install Specific Major Version + +```yaml +- hosts: servers + roles: + - role: mariadb + vars: + mariadb_major_version: "11" +``` + +### Install Specific Minor Version + +```yaml +- hosts: servers + roles: + - role: mariadb + vars: + mariadb_major_version: "11" + mariadb_minor_version: "8" # Installs latest 11.8.x +``` + +### Upgrade MariaDB Version + +```yaml +- hosts: servers + roles: + - role: mariadb + vars: + mariadb_major_version: "12" + mariadb_force_upgrade: true +``` + +## Usage Scenarios + +### Fresh Installation +```yaml +# Install latest MariaDB 12 +- role: mariadb + +# Install latest MariaDB 11 +- role: mariadb + vars: + mariadb_major_version: "11" + +# Install MariaDB 11.8.x (latest patch) +- role: mariadb + vars: + mariadb_major_version: "11" + mariadb_minor_version: "8" +``` + +### Version Upgrades +```yaml +# Upgrade from MariaDB 11 to 12 +- role: mariadb + vars: + mariadb_major_version: "12" + mariadb_force_upgrade: true + +# Upgrade to specific minor version +- role: mariadb + vars: + mariadb_major_version: "12" + mariadb_minor_version: "1" + mariadb_force_upgrade: true +``` + +## How It Works + +### Normal Installation Process +1. Install prerequisites (curl, ca-certificates) +2. Download and run official MariaDB repository setup script +3. Update apt cache +4. Install MariaDB packages +5. Start and enable MariaDB service + +### Upgrade Process (`mariadb_force_upgrade: true`) +1. Stop MariaDB service +2. Remove existing repository configuration +3. Setup new repository with target version +4. Update apt cache +5. Upgrade packages to new version +6. Run `mysql_upgrade` for schema compatibility +7. Restart MariaDB service + +### Version Resolution Logic +- **Repository**: Uses major version only (e.g., `mariadb-11.rolling`) +- **Packages**: + - Without minor version: `mariadb-server` (latest available) + - With minor version: `mariadb-server=1:11.8*` (latest patch in minor series) + +## File Structure + +``` +mariadb/ +├── README.md +├── LICENSE +├── meta/ +│ └── main.yml # Role metadata +├── defaults/ +│ └── main.yml # Default variables +├── tasks/ +│ ├── main.yml # Main task inclusion +│ ├── install.yml # Installation tasks +│ └── upgrade.yml # Upgrade-specific tasks +└── handlers/ + └── main.yml # Service handlers +``` + +## Handlers + +The role includes handlers for MariaDB service management: +- `restart mariadb`: Restarts the MariaDB service + +## Examples with Command Line + +### Install with specific version +```bash +ansible-playbook playbook.yml -e "mariadb_major_version=11" +``` + +### Upgrade to new version +```bash +ansible-playbook playbook.yml -e "mariadb_major_version=12 mariadb_force_upgrade=true" +``` + +### Install specific minor version +```bash +ansible-playbook playbook.yml -e "mariadb_major_version=11 mariadb_minor_version=8" +``` + +## Troubleshooting + +### Repository Issues +If you encounter repository-related issues, try forcing a repository update: +```yaml +mariadb_force_upgrade: true +``` + +### Version Conflicts +When upgrading between major versions, always use: +```yaml +mariadb_force_upgrade: true +``` + +### Service Issues +The role automatically handles service management, but you can manually check: +```bash +systemctl status mariadb +``` + +## License + +MIT + +## Author Information + +This role was created by [Ludovic Cartier](mailto:ludovic@brainsys.io) at [brainsys](https://brainsys.io). + +--- + +**Repository**: https://git.brainsys.io/ansible-roles/mariadb +**Issues**: https://git.brainsys.io/ansible-roles/mariadb/issues \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..f1baf86 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,13 @@ +--- +# MariaDB version configuration +# Major version for repository setup (supported: 10, 11, 12) +mariadb_major_version: "12" + +# Minor version for package installation (optional) +# If not specified, installs the latest available version +# Format: "minor" (e.g., "8" for latest 11.8.x version) +# mariadb_minor_version: "8" + +# Force repository update (useful when upgrading major versions) +# Set to true to force recreation of repository configuration +mariadb_force_upgrade: false \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..af28c87 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart mariadb + systemd_service: + name: mariadb + state: restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..91c58db --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,9 @@ +--- +galaxy_info: + author: Ludovic Cartier + description: install & configure MariaDB + company: brainsys + license: MIT + min_ansible_version: 2.8 + issue_tracker_url: https://git.brainsys.io/ansible-roles/mariadb/issues + github_branch: main diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..2d336ff --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,47 @@ +--- +- name: mariadb | install prerequisite packages + ansible.builtin.apt: + name: + - curl + - ca-certificates + state: present + update_cache: yes + +- name: mariadb | download and run mariadb repository setup script + shell: | + curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash -s -- --skip-maxscale --mariadb-server-version=mariadb-{{ mariadb_major_version }}.rolling + args: + creates: /etc/apt/sources.list.d/mariadb.list + become: true + +- name: mariadb | update apt cache after adding repository + ansible.builtin.apt: + update_cache: yes + +- name: mariadb | install mariadb server and client (latest minor version) + ansible.builtin.apt: + name: + - mariadb-server + - mariadb-client + state: present + notify: + - restart mariadb + when: + - mariadb_minor_version is not defined + +- name: mariadb | install mariadb server and client (specific minor version) + apt: + name: + - "mariadb-server=1:{{ mariadb_major_version }}.{{ mariadb_minor_version }}*" + - "mariadb-client=1:{{ mariadb_major_version }}.{{ mariadb_minor_version }}*" + state: present + notify: + - restart mariadb + when: + - mariadb_minor_version is defined + +- name: mariadb | ensure mariadb service is started and enabled + service: + name: mariadb + state: started + enabled: true diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..e99c580 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- name: mariadb | requirements + include_tasks: requirements.yml + +- name: mariadb | upgrade + include_tasks: upgrade.yml + when: mariadb_force_upgrade | bool + +- name: mariadb | installation + include_tasks: install.yml + when: not mariadb_force_upgrade | bool \ No newline at end of file diff --git a/tasks/requirements.yml b/tasks/requirements.yml new file mode 100644 index 0000000..9c94710 --- /dev/null +++ b/tasks/requirements.yml @@ -0,0 +1,15 @@ +--- +- name: mariadb | apt update cache + ansible.builtin.apt: + update_cache: yes + cache_valid_time: 86400 + +- name: mariadb | install requirements + ansible.builtin.apt: + name: + - apt-transport-https + - lsb-release + - ca-certificates + - curl + state: present + diff --git a/tasks/upgrade.yml b/tasks/upgrade.yml new file mode 100644 index 0000000..0ed7287 --- /dev/null +++ b/tasks/upgrade.yml @@ -0,0 +1,49 @@ +--- +- name: mariadb | stop mariadb service before upgrade + service: + name: mariadb + state: stopped + ignore_errors: true + +- name: mariadb | remove existing repository file (force upgrade) + file: + path: /etc/apt/sources.list.d/mariadb.list + state: absent + +- name: mariadb | download and run mariadb repository setup script (force upgrade) + shell: | + curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash -s -- --skip-maxscale --mariadb-server-version=mariadb-{{ mariadb_major_version }}.rolling + become: true + +- name: mariadb | update apt cache after repository change + ansible.builtin.apt: + update_cache: yes + +- name: mariadb | upgrade mariadb server and client (latest minor version) + ansible.builtin.apt: + name: + - mariadb-server + - mariadb-client + state: latest + notify: + - restart mariadb + when: + mariadb_minor_version is not defined + +- name: mariadb | upgrade mariadb server and client (specific minor version) + ansible.builtin.apt: + name: + - "mariadb-server=1:{{ mariadb_major_version }}.{{ mariadb_minor_version }}*" + - "mariadb-client=1:{{ mariadb_major_version }}.{{ mariadb_minor_version }}*" + state: latest + force: yes + notify: + - restart mariadb + when: + - mariadb_minor_version is defined + +- name: mariadb | run mysql_upgrade after version change + shell: mysql_upgrade + ignore_errors: true + notify: + - restart mariadb \ No newline at end of file