first draft

This commit is contained in:
Ludovic Cartier
2025-12-18 11:42:56 +01:00
parent 20fba6cb9b
commit d81541660e
13 changed files with 228 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.vscode

9
LICENSE Normal file
View File

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

View File

@@ -0,0 +1,47 @@
# Ansible Role: Percona Server
Installs and manages Percona Server on Debian.
## Requirements
None.
## Role Variables
Available variables are listed below, along with default values (see `defaults/main.yml`):
```yaml
percona_version: "8.4"
percona_root_password: "root_password_change_me"
percona_bind_address: "127.0.0.1"
percona_port: 3306
percona_databases: []
percona_users: []
```
## Dependencies
None.
## Example Playbook
```yaml
- hosts: database
roles:
- role: percona
vars:
percona_version: "8.4"
percona_root_password: "secure_password"
percona_databases:
- name: app_db
collation: utf8mb4_general_ci
encoding: utf8mb4
percona_users:
- name: app_user
password: "app_password"
priv: "app_db.*:ALL"
```
## License
MIT

33
defaults/main.yml Normal file
View File

@@ -0,0 +1,33 @@
---
# Percona Server version. Supported values: "8.0", "8.4"
percona_version: "8.4"
# Percona release setup package URL
percona_release_package_url: "https://repo.percona.com/apt/percona-release_latest.generic_all.deb"
# MySQL root password
percona_root_password: "root_password_change_me"
# Bind address
percona_bind_address: "127.0.0.1"
# Port
percona_port: 3306
# Databases to create
# Example:
# percona_databases:
# - name: my_db
# collation: utf8mb4_general_ci
# encoding: utf8mb4
percona_databases: []
# Users to create
# Example:
# percona_users:
# - name: my_user
# password: my_password
# host: "%"
# priv: "my_db.*:ALL"
percona_users: []

5
handlers/main.yml Normal file
View File

@@ -0,0 +1,5 @@
---
- name: Restart Percona Server
service:
name: mysql
state: restarted

18
meta/main.yml Normal file
View File

@@ -0,0 +1,18 @@
---
galaxy_info:
author: Ludovic Cartier
description: install & configure Percona Server
company: brainsys
license: MIT
min_ansible_version: "2.9"
issue_tracker_url: https://git.brainsys.io/ansible-roles/percona/issues
github_branch: main
platforms:
- name: Debian
versions:
- all
galaxy_tags:
- database
- percona
- mysql
dependencies: []

22
tasks/configure.yml Normal file
View File

@@ -0,0 +1,22 @@
---
- name: percona | configure Percona Server
template:
src: my.cnf.j2
dest: /etc/mysql/conf.d/01-ansible.cnf
mode: '0644'
notify: Restart Percona Server
- name: percona | ensure Percona Server is started and enabled
service:
name: mysql
state: started
enabled: yes
- name: percona | update MySQL root password
mysql_user:
name: root
host: localhost
password: "{{ percona_root_password }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
priv: "*.*:ALL,GRANT"
ignore_errors: true # In case password is already set and socket auth is disabled

10
tasks/databases.yml Normal file
View File

@@ -0,0 +1,10 @@
---
- name: percona | create databases
mysql_db:
name: "{{ item.name }}"
collation: "{{ item.collation | default(omit) }}"
encoding: "{{ item.encoding | default(omit) }}"
state: present
login_user: root
login_password: "{{ percona_root_password }}"
loop: "{{ percona_databases }}"

27
tasks/install.yml Normal file
View File

@@ -0,0 +1,27 @@
---
- name: percona | download Percona release package
get_url:
url: "{{ percona_release_package_url }}"
dest: /tmp/percona-release_latest.generic_all.deb
mode: '0644'
- name: percona | install Percona release package
apt:
deb: /tmp/percona-release_latest.generic_all.deb
state: present
- name: percona | determine Percona release string
set_fact:
percona_release_string: >-
{% if percona_version == '8.4' %}ps-84-lts{% elif percona_version == '8.0' %}ps-80{% else %}ps-80{% endif %}
- name: percona | enable Percona repository
command: "percona-release setup -y {{ percona_release_string }}"
args:
creates: "/etc/apt/sources.list.d/percona-{{ percona_release_string }}-release.list"
- name: percona | install Percona Server
apt:
name: percona-server-server
state: present
update_cache: yes

16
tasks/main.yml Normal file
View File

@@ -0,0 +1,16 @@
---
- name: percona | requirements
include_tasks: requirements.yml
- name: percona | installation
include_tasks: install.yml
- name: percona | configuration
include_tasks: configure.yml
- name: percona | databases
include_tasks: databases.yml
- name: percona | users
include_tasks: users.yml

20
tasks/requirements.yml Normal file
View File

@@ -0,0 +1,20 @@
---
- name: percona | apt update cache
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 86400
- name: percona | install requirements
ansible.builtin.apt:
name:
- apt-transport-https
- lsb-release
- ca-certificates
- curl
- gnupg2
state: present
- name: percona | install python3-pymysql for database management
ansible.builtin.apt:
name: python3-pymysql
state: present

11
tasks/users.yml Normal file
View File

@@ -0,0 +1,11 @@
---
- name: percona | create users
mysql_user:
name: "{{ item.name }}"
password: "{{ item.password }}"
host: "{{ item.host | default('%') }}"
priv: "{{ item.priv | default('*.*:USAGE') }}"
state: present
login_user: root
login_password: "{{ percona_root_password }}"
loop: "{{ percona_users }}"

9
templates/my.cnf.j2 Normal file
View File

@@ -0,0 +1,9 @@
[mysqld]
bind-address = {{ percona_bind_address }}
port = {{ percona_port }}
# Character set and collation
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
# Other settings can be added here