Compare commits

...

16 commits
v2.0.1 ... main

Author SHA1 Message Date
951ec2a4c8 test: fix syntax for ansible lint
All checks were successful
/ lint (push) Successful in 8s
/ molecule (push) Successful in 1m18s
2024-05-09 12:30:27 +02:00
2c32003804 test: add forgejo workflow
Some checks failed
/ lint (push) Failing after 8s
/ molecule (push) Successful in 1m16s
2024-05-09 11:48:22 +02:00
0efdcb045e test: use personal docker registry 2024-05-07 08:59:48 +02:00
5eb6a71466 fix: change gpg key 2024-03-13 21:46:38 +01:00
6361a81fe5 chore: fix syntax for ansible-lint 2024-03-13 21:46:37 +01:00
a5a31223c0 feat: add debian 12 support 2024-03-13 21:46:37 +01:00
e109a23cfa fix: change key server 2024-03-13 21:46:36 +01:00
fcbf14dc3a test: add gitlab-ci 2024-03-13 21:46:35 +01:00
753770e77d release: version 2.1.0 2021-08-22 16:39:03 +02:00
03dcb51ea1 test: add support debian 11 2021-08-22 16:36:45 +02:00
51fbef2480 fix: replace no_log to loop label 2021-08-22 16:36:42 +02:00
837a6cce63 chore: use FQCN for module name 2021-08-22 16:36:40 +02:00
611d8234ad test: minor fix 2021-08-22 16:36:36 +02:00
b9070661f9 fix: bug with multiple privileges 2021-08-22 16:36:32 +02:00
2dbbaf8147 fix: minor change in readme 2020-03-28 17:38:38 +01:00
08f588d4aa chore: remove old rubocop file 2020-03-28 11:34:12 +01:00
15 changed files with 186 additions and 160 deletions

View file

@ -0,0 +1,18 @@
---
on: [push]
jobs:
lint:
runs-on: docker
container:
image: code.waks.be/nishiki/molecule:docker
steps:
- uses: actions/checkout@v3
- run: ansible-lint .
- run: yamllint .
molecule:
runs-on: docker
container:
image: code.waks.be/nishiki/molecule:docker
steps:
- uses: actions/checkout@v3
- run: molecule test

10
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,10 @@
---
image: nishiki/molecule:docker
before_script:
- molecule --version
molecule:
stage: test
script:
- molecule test

View file

@ -1,38 +0,0 @@
---
AllCops:
Exclude:
- db/**/*
- config/**/*
- Vagrantfile
TargetRubyVersion: 2.4
Naming/AccessorMethodName:
Enabled: false
Lint/RescueWithoutErrorClass:
Enabled: false
Metrics/LineLength:
Max: 120
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/PerceivedComplexity:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Metrics/ClassLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Style/NumericLiteralPrefix:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/CommandLiteral:
Enabled: true
EnforcedStyle: percent_x
Style/Documentation:
Enabled: false

View file

@ -2,11 +2,11 @@
extends: default extends: default
ignore: | ignore: |
.kitchen/* .kitchen*
vendor/ vendor/
.forgejo/
rules: rules:
line-length: line-length:
max: 120 max: 120
level: warning level: warning
truthy: false

View file

@ -3,28 +3,48 @@
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
Which is based on [Keep A Changelog](http://keepachangelog.com/) Which is based on [Keep A Changelog](http://keepachangelog.com/)
## [Unreleased] ## Unreleased
## [v2.0.1] - 2020-03-28 ### Fixed
- fix: change gpg key
## v2.1.0 - 2021-08-22
### Added
- test: add support debian 11
### Fixed
- fix: bug with multiple privileges
### Changed
- chore: use FQCN for module name
- fix: replace no_log to loop label
- test: use personal docker registry
## v2.0.1 - 2020-03-28
### Changed ### Changed
- fix: remove default value for mariadb_password - fix: remove default value for mariadb_password
- test: replace kitchen to molecule - test: replace kitchen to molecule
## [v2.0.0] - 2019-06-05 ## v2.0.0 - 2019-06-05
- breaking: remove support for ansible < 2.8 - breaking: remove support for ansible < 2.8
- feat: add official repository - feat: add official repository
- feat: remove unused users in init - feat: remove unused users in init
- feat: install database if datadir doesn't exist - feat: install database if datadir doesn't exist
## [v1.0.1] - 2019-03-16 ## v1.0.1 - 2019-03-16
- fix: add client-server option in default configuration - fix: add client-server option in default configuration
- fix: install python-mysqldb package - fix: install python-mysqldb package
- test: add tests with travis-ci - test: add tests with travis-ci
## [v1.0.0] - 2019-02-23 ## v1.0.0 - 2019-02-23
- first version - first version

View file

@ -1,20 +1,22 @@
# Ansible role: MariaDB # Ansible role: MariaDB
[![Version](https://img.shields.io/badge/latest_version-2.0.1-green.svg)](https://git.yaegashi.fr/nishiki/ansible-role-mariadb/releases) [![Version](https://img.shields.io/badge/latest_version-2.1.0-green.svg)](https://code.waks.be/nishiki/ansible-role-mariadb/releases)
[![Build Status](https://travis-ci.org/nishiki/ansible-role-mariadb.svg?branch=master)](https://travis-ci.org/nishiki/ansible-role-mariadb) [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://code.waks.be/nishiki/ansible-role-mariadb/src/branch/master/LICENSE)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://git.yaegashi.fr/nishiki/ansible-role-mariadb/src/branch/master/LICENSE) [![Build](https://code.waks.be/nishiki/ansible-role-mariadb/actions/workflows/molecule.yml/badge.svg?branch=main)](https://code.waks.be/nishiki/ansible-role-mariadb/actions?workflow=molecule.yml)
Install and configure MariaDB Install and configure MariaDB
## Requirements ## Requirements
* Ansible >= 2.8 - Ansible >= 2.9
* Debian Stretch and Buster - Debian
- Bullseye
- Bookworm
## Role variables ## Role variables
| Name | Type | Required | Default | Comment | | Name | Type | Required | Default | Comment |
|---------------------------------|-------|----------|--------|----------------------------------------| | ------------------------------- | ----- | -------- | ------- | -------------------------------------- |
| mariadb_use_official_repository | bool | no | true | use the official repository | | mariadb_use_official_repository | bool | no | true | use the official repository |
| mariadb_branch | str | no | 10.3 | the branch version to install | | mariadb_branch | str | no | 10.3 | the branch version to install |
| mariadb_user | str | no | root | login to connect on mariadb | | mariadb_user | str | no | root | login to connect on mariadb |
@ -28,7 +30,7 @@ Install and configure MariaDB
### mariadb_users ### mariadb_users
| Name | Type | Required | Default | Comment | | Name | Type | Required | Default | Comment |
|------------|-------|----------|---------|-----------------------------------------------------------| | ---------- | ----- | -------- | ------- | --------------------------------------------------------- |
| name | str | yes | | the username | | name | str | yes | | the username |
| host | str | yes | | the mysql user host | | host | str | yes | | the mysql user host |
| password | str | yes | | the user password | | password | str | yes | | the user password |
@ -49,7 +51,7 @@ Example:
### mariadb_databases ### mariadb_databases
| Name | Type | Required | Default | Comment | | Name | Type | Required | Default | Comment |
|------------|-------|----------|---------|-----------------------------------------------------------| | ----- | ---- | -------- | ------- | -------------------------------------------- |
| name | str | yes | | the dabase name | | name | str | yes | | the dabase name |
| state | str | no | present | if state is `absent` the database is deleted | | state | str | no | present | if state is `absent` the database is deleted |
@ -83,7 +85,7 @@ Example:
privileges: privileges:
- 'myappli.*:ALL' - 'myappli.*:ALL'
mariadb_databases: mariadb_databases:
- myappli - name: myappli
mariadb_config: mariadb_config:
server-id: 1 server-id: 1
bind-address: 0.0.0.0 bind-address: 0.0.0.0
@ -95,10 +97,10 @@ Example:
### Test with molecule and docker ### Test with molecule and docker
* install [docker](https://docs.docker.com/engine/installation/) - install [docker](https://docs.docker.com/engine/installation/)
* install `python3` and `python3-pip` - install `python3` and `python3-pip`
* install molecule and dependencies `pip3 install molecule 'molecule[docker]' docker ansible-lint testinfra yamllint` - install molecule and dependencies `pip3 install molecule molecule-docker docker ansible-lint pytest-testinfra yamllint`
* run `molecule test` - run `molecule test`
## License ## License

View file

@ -1,13 +1,13 @@
--- ---
mariadb_use_official_repository: yes mariadb_use_official_repository: true
mariadb_branch: 10.3 mariadb_branch: 10.6
mariadb_repository: | mariadb_repository: |
deb http://mariadb.mirrors.ovh.net/MariaDB/repo/{{ mariadb_branch }}/debian {{ ansible_distribution_release }} main deb http://mariadb.mirrors.ovh.net/MariaDB/repo/{{ mariadb_branch }}/debian {{ ansible_distribution_release }} main
mariadb_repository_key_id: '0xF1656F24C74CD1D8' mariadb_repository_key_id: '0xF1656F24C74CD1D8'
mariadb_repository_key_server: keyserver.ubuntu.com mariadb_repository_key_server: hkp://keyserver.ubuntu.com:80
mariadb_user: root mariadb_user: root
mariadb_master: no mariadb_master: false
mariadb_autorestart: no mariadb_autorestart: false
mariadb_users: [] mariadb_users: []
mariadb_databases: [] mariadb_databases: []
mariadb_config: {} mariadb_config: {}

View file

@ -1,6 +1,6 @@
--- ---
- name: restart mariadb - name: Restart mariadb
service: ansible.builtin.service:
name: mysql name: mysql
state: restarted state: restarted
when: mariadb_autorestart|bool when: mariadb_autorestart|bool

View file

@ -1,17 +1,18 @@
--- ---
galaxy_info: galaxy_info:
role_name: mariadb role_name: mariadb
namespace: nishiki
author: Adrien Waksberg author: Adrien Waksberg
company: Adrien Waksberg company: Adrien Waksberg
description: Install and configure mariadb description: Install and configure mariadb
license: Apache2 license: Apache2
min_ansible_version: 2.8 min_ansible_version: "2.9"
platforms: platforms:
- name: Debian - name: Debian
versions: versions:
- stretch - bullseye
- buster - bookworm
galaxy_tags: galaxy_tags:
- database - database

View file

@ -1,6 +1,8 @@
--- ---
- name: Converge - name: Converge
hosts: all hosts: all
roles:
- ansible-role-mariadb
vars: vars:
mariadb_password: secret mariadb_password: secret
mariadb_autorestart: yes mariadb_autorestart: yes
@ -19,5 +21,8 @@
password: test password: test
privileges: privileges:
- 'test.*:ALL' - 'test.*:ALL'
roles:
- ansible-role-mariadb pre_tasks:
- name: update apt cache
ansible.builtin.apt:
update_cache: true

View file

@ -2,17 +2,23 @@
driver: driver:
name: docker name: docker
platforms: platforms:
- name: debian10 - name: debian12
image: nishiki/debian10:molecule image: code.waks.be/nishiki/molecule:debian12
privileged: true privileged: true
volumes: volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro - /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
command: /bin/systemd command: /bin/systemd
capabilities: capabilities:
- SYS_ADMIN - SYS_ADMIN
provisioner:
inventory:
host_vars:
debian12:
mariadb_use_official_repository: false
lint: | lint: |
set -e set -e
yamllint . yamllint .
ansible-lint ansible-lint .
verifier: verifier:
name: testinfra name: testinfra

View file

@ -2,7 +2,7 @@ import os, re
import testinfra.utils.ansible_runner import testinfra.utils.ansible_runner
def test_packages(host): def test_packages(host):
for package_name in ['mariadb-server', 'python-mysqldb']: for package_name in ['mariadb-server', 'python3-mysqldb']:
package = host.package(package_name) package = host.package(package_name)
assert package.is_installed assert package.is_installed
@ -42,7 +42,7 @@ def test_root_user(host):
def test_grant_access(host): def test_grant_access(host):
result = host.check_output('mysql -uroot -psecret -e "show grants for toto@\'%\'"') result = host.check_output('mysql -uroot -psecret -e "show grants for toto@\'%\'"')
assert "GRANT ALL PRIVILEGES ON `test`.* TO 'toto'@'%'" in result assert "GRANT ALL PRIVILEGES ON `test`.* TO `toto`@`%`" in result
def test_logbin_enabled(host): def test_logbin_enabled(host):
result = host.check_output('mysql -uroot -psecret -e "show variables where variable_name = \'log_bin\'"') result = host.check_output('mysql -uroot -psecret -e "show variables where variable_name = \'log_bin\'"')

View file

@ -1,6 +1,6 @@
--- ---
- name: create the data directory - name: Create the data directory
file: ansible.builtin.file:
path: '{{ mariadb_full_config.mysqld.datadir }}' path: '{{ mariadb_full_config.mysqld.datadir }}'
owner: '{{ mariadb_full_config.mysqld.user }}' owner: '{{ mariadb_full_config.mysqld.user }}'
group: root group: root
@ -8,8 +8,8 @@
state: directory state: directory
tags: mariadb tags: mariadb
- name: initialize database - name: Initialize database # noqa no-changed-when
command: ansible.builtin.command:
args: args:
argv: argv:
- mysql_install_db - mysql_install_db
@ -17,37 +17,34 @@
- '--user={{ mariadb_full_config.mysqld.user }}' - '--user={{ mariadb_full_config.mysqld.user }}'
- '--skip-name-resolve' - '--skip-name-resolve'
- '--no-defaults' - '--no-defaults'
when: True
tags: mariadb tags: mariadb
- name: start mariadb - name: Start mariadb
systemd: ansible.builtin.service:
name: mysql name: mysql
state: started state: started
tags: mariadb tags: mariadb
- name: wait mysql start - name: Wait mysql start
pause: ansible.builtin.pause:
seconds: 5 seconds: 5
tags: mariadb tags: mariadb
- name: set root password - name: Set root password # noqa no-changed-when
command: 'mysqladmin -u root password {{ mariadb_password }}' ansible.builtin.command: 'mysqladmin -u root password {{ mariadb_password }}'
when: True
tags: mariadb tags: mariadb
- name: remove anonymous users - name: Remove anonymous users
mysql_user: community.mysql.mysql_user:
name: '' name: ''
host_all: yes host_all: true
state: absent state: absent
login_user: '{{ mariadb_user }}' login_user: '{{ mariadb_user }}'
login_password: '{{ mariadb_password }}' login_password: '{{ mariadb_password }}'
no_log: true
tags: mariadb tags: mariadb
- name: remove root user without password - name: Remove root user without password
mysql_user: community.mysql.mysql_user:
name: root name: root
host: '{{ item }}' host: '{{ item }}'
state: absent state: absent
@ -57,5 +54,4 @@
- 127.0.0.1 - 127.0.0.1
- '::1' - '::1'
- '{{ ansible_nodename }}' - '{{ ansible_nodename }}'
no_log: true
tags: mariadb tags: mariadb

View file

@ -1,69 +1,79 @@
--- ---
- import_tasks: repo.yml - name: Install dependencies packages
when: mariadb_use_official_repository|bool ansible.builtin.package:
name:
- name: install package - gpg
package:
name: '{{ packages }}'
vars:
packages:
- mariadb-server
- python-mysqldb
- python3-mysqldb - python3-mysqldb
retries: 2 retries: 2
register: result register: result
until: result is succeeded until: result is succeeded
tags: mariadb tags: mariadb
- name: copy configuration file - name: Install official repository
template: ansible.builtin.import_tasks: repo.yml
when: mariadb_use_official_repository|bool
- name: Install package
ansible.builtin.package:
name:
- mariadb-server
retries: 2
register: result
until: result is succeeded
tags: mariadb
- name: Copy configuration file
ansible.builtin.template:
src: my.cnf.j2 src: my.cnf.j2
dest: /etc/mysql/my.cnf dest: /etc/mysql/my.cnf
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
notify: restart mariadb notify: Restart mariadb
tags: mariadb tags: mariadb
- name: check if datadir exist - name: Check if datadir exist
stat: ansible.builtin.stat:
path: '{{ mariadb_full_config.mysqld.datadir }}' path: "{{ mariadb_full_config.mysqld.datadir }}"
register: st register: st
tags: mariadb tags: mariadb
- import_tasks: initdb.yml - name: Initialize the database
ansible.builtin.import_tasks: initdb.yml
when: not st.stat.exists when: not st.stat.exists
- name: enable and start the service - name: Enable and start the service
service: ansible.builtin.service:
name: mysql name: mysql
state: started state: started
enabled: yes enabled: true
tags: mariadb tags: mariadb
- name: manage users - name: Manage users
mysql_user: community.mysql.mysql_user:
name: '{{ item.name }}' name: "{{ item.name }}"
host: '{{ item.host }}' host: "{{ item.host }}"
password: '{{ item.password }}' password: "{{ item.password }}"
priv: '{{ item.privileges|default("")|join(",") }}' priv: "{{ item.privileges | default('') | join('/') }}"
state: '{{ item.state|default("present") }}' state: "{{ item.state | default('present') }}"
login_user: '{{ mariadb_user }}' login_user: "{{ mariadb_user }}"
login_password: '{{ mariadb_password }}' login_password: "{{ mariadb_password }}"
loop: '{{ mariadb_users }}' loop: "{{ mariadb_users }}"
loop_control:
label: "{{ item.name }}@{{ item.host }}"
run_once: true run_once: true
no_log: true
when: mariadb_master|bool when: mariadb_master|bool
tags: mariadb tags: mariadb
- name: manage databases - name: Manage databases
mysql_db: community.mysql.mysql_db:
name: '{{ item.name }}' name: "{{ item.name }}"
state: '{{ item.state|default("present") }}' state: "{{ item.state | default('present') }}"
login_user: '{{ mariadb_user }}' login_user: "{{ mariadb_user }}"
login_password: '{{ mariadb_password }}' login_password: "{{ mariadb_password }}"
loop: '{{ mariadb_databases }}' loop: "{{ mariadb_databases }}"
loop_control:
label: "{{ item.name }}"
run_once: true run_once: true
no_log: true
when: mariadb_master|bool when: mariadb_master|bool
tags: mariadb tags: mariadb

View file

@ -1,14 +1,10 @@
--- ---
- name: add gpg key for mariadb repository - name: Add gpg key for mariadb repository
apt_key: ansible.builtin.apt_key:
keyserver: '{{ mariadb_repository_key_server }}' url: https://supplychain.mariadb.com/MariaDB-Server-GPG-KEY
id: '{{ mariadb_repository_key_id }}'
retries: 2
register: result
until: result is succeeded
tags: mariadb tags: mariadb
- name: add official repo - name: Add official repo
apt_repository: ansible.builtin.apt_repository:
repo: '{{ mariadb_repository }}' repo: "{{ mariadb_repository }}"
tags: mariadb tags: mariadb