mirror of
https://github.com/HanXHX/ansible-mysql.git
synced 2026-02-28 10:32:10 +07:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
239ce0dd6c | ||
|
|
f7235d38b9 | ||
|
|
6a9d12c5eb | ||
|
|
fe7d09b9cd | ||
|
|
69f86f60ba |
11
README.md
11
README.md
@@ -6,11 +6,11 @@ MariaDB (MySQL) Ansible role for Debian
|
|||||||
Install and configure MariaDB (Galera Cluster). Manage replication (master/slave). Create users and databases.
|
Install and configure MariaDB (Galera Cluster). Manage replication (master/slave). Create users and databases.
|
||||||
|
|
||||||
| OS | Origin | MariaDB versions |
|
| OS | Origin | MariaDB versions |
|
||||||
| --------------- | --------- | ------------------------- |
|
| --------------- | --------- | ----------------- |
|
||||||
| Debian Buster | Debian | 10.3 |
|
| Debian Buster | Debian | 10.3 |
|
||||||
| Debian Buster | Upstream | 10.3 to 10.6 |
|
| Debian Buster | Upstream | Up from 10.3 |
|
||||||
| Debian Bullseye | Debian | 10.5 |
|
| Debian Bullseye | Debian | 10.5 |
|
||||||
| Debian Bullseye | Upstream | 10.5 to 10.6 |
|
| Debian Bullseye | Upstream | Up from 10.5 |
|
||||||
|
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
@@ -61,12 +61,11 @@ Check "priv" syntax in [mysql\_user module documentation](http://docs.ansible.co
|
|||||||
|
|
||||||
### Packaging
|
### Packaging
|
||||||
|
|
||||||
- `mariadb_version`: depends Debian version
|
- `mariadb_upstream_version`: depends Debian version
|
||||||
- `mariadb_repository`: MariaDB upstream APT repository (see: [MariaDB repositories tool](https://downloads.mariadb.org/mariadb/repositories))
|
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
|
|
||||||
- `mariadb_debug_role`: boolean, set true to disable no_log hidding
|
- `mariadb_debug_role`: boolean, set true to disable `no_log` hidding
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
------------
|
------------
|
||||||
|
|||||||
8
Vagrantfile
vendored
8
Vagrantfile
vendored
@@ -79,10 +79,6 @@ Vagrant.configure("2") do |config|
|
|||||||
d.has_ssh = true
|
d.has_ssh = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:os_name].include? "bullseye"
|
|
||||||
m.vm.provision "shell", inline: "[ -f '/root/first_provision' ] || (apt-get update -qq && apt-get -y dist-upgrade && touch /root/first_provision)"
|
|
||||||
end
|
|
||||||
|
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
@@ -106,10 +102,6 @@ Vagrant.configure("2") do |config|
|
|||||||
v.memory = 512
|
v.memory = 512
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts[:os_name].include? "bullseye"
|
|
||||||
m.vm.provision "shell", inline: "[ -f '/root/first_provision' ] || (apt-get update -qq && apt-get -y dist-upgrade && touch /root/first_provision)"
|
|
||||||
end
|
|
||||||
|
|
||||||
m.vm.provision "ansible" do |ansible|
|
m.vm.provision "ansible" do |ansible|
|
||||||
ansible.playbook = "tests/test.yml"
|
ansible.playbook = "tests/test.yml"
|
||||||
ansible.verbose = 'vv'
|
ansible.verbose = 'vv'
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
mariadb_origin: 'default'
|
mariadb_origin: 'default'
|
||||||
mariadb_use_galera: false
|
mariadb_use_galera: false
|
||||||
mariadb_notify_restart: true
|
mariadb_notify_restart: true
|
||||||
mariadb_upstream_apt_src: false
|
|
||||||
|
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
# Configuration
|
# Configuration
|
||||||
@@ -115,14 +114,10 @@ mariadb_databases: []
|
|||||||
mariadb_users: []
|
mariadb_users: []
|
||||||
|
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
# MariaDB
|
# MariaDB Upstream
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
mariadb_version: '10.6'
|
mariadb_upstream_setup_script: 'https://r.mariadb.com/downloads/mariadb_repo_setup'
|
||||||
mariadb_mirror_domain: "ftp.igh.cnrs.fr"
|
mariadb_upstream_version: '10.6'
|
||||||
# See: https://downloads.mariadb.org/mariadb/repositories
|
|
||||||
mariadb_repository: "http://{{ mariadb_mirror_domain }}/pub/mariadb/repo/{{ mariadb_version }}/debian"
|
|
||||||
mariadb_key_server: "keyserver.ubuntu.com"
|
|
||||||
mariadb_key_ids: ['0xcbcb082a1bb943db', '0xf1656f24c74cd1d8']
|
|
||||||
|
|
||||||
# -------------------------------------
|
# -------------------------------------
|
||||||
# Galera
|
# Galera
|
||||||
|
|||||||
@@ -4,25 +4,36 @@
|
|||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: gpg
|
name: gpg
|
||||||
|
|
||||||
- name: APT_KEY | Install MariaDB key
|
- name: COMMAND | Check indempotent
|
||||||
ansible.builtin.apt_key:
|
ansible.builtin.command: 'grep -q "{{ mariadb_upstream_version }}" /etc/apt/sources.list.d/mariadb.list'
|
||||||
keyserver: "{{ mariadb_key_server }}"
|
register: check_idempotent
|
||||||
id: "{{ item }}"
|
failed_when: false
|
||||||
loop: "{{ mariadb_key_ids }}"
|
changed_when: false
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy APT pinning (prevent upgrades from Debian)
|
- block:
|
||||||
ansible.builtin.template:
|
|
||||||
src: etc/apt/preferences.d/95-mariadb.j2
|
- name: GET_URL | Download MariaDB setup script
|
||||||
dest: /etc/apt/preferences.d/95-mariadb
|
ansible.builtin.get_url:
|
||||||
mode: 0644
|
url: '{{ mariadb_upstream_setup_script }}'
|
||||||
|
dest: '/tmp/mariadb_repo_setup'
|
||||||
|
mode: 0755
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
|
|
||||||
- name: APT_REPOSITORY | Add MariaDB repository
|
- name: COMMAND | Launch MariaDB upstream setup script
|
||||||
ansible.builtin.apt_repository:
|
ansible.builtin.command: '/tmp/mariadb_repo_setup --mariadb-server-version={{ mariadb_upstream_version }}'
|
||||||
repo: 'deb {{ mariadb_repository }} {{ ansible_distribution_release }} main'
|
changed_when: true
|
||||||
|
|
||||||
- name: APT_REPOSITORY | Add MariaDB (src) repository
|
- name: FILE | Remove setup script
|
||||||
ansible.builtin.apt_repository:
|
ansible.builtin.file:
|
||||||
repo: 'deb-src {{ mariadb_repository }} {{ ansible_distribution_release }} main'
|
path: '/tmp/mariadb_repo_setup'
|
||||||
when: mariadb_upstream_apt_src
|
state: absent
|
||||||
|
|
||||||
|
when: check_idempotent.rc > 0
|
||||||
|
|
||||||
|
- name: SHELL | Remove useless old files
|
||||||
|
ansible.builtin.shell: 'rm -f /etc/apt/sources.list.d/mariadb.list.old_*'
|
||||||
|
args:
|
||||||
|
removes: /etc/apt/sources.list.d/mariadb.list.old_1
|
||||||
|
tags:
|
||||||
|
- skip_ansible_lint
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
community.mysql.mysql_db:
|
community.mysql.mysql_db:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
state: present
|
state: present
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
loop: "{{ mariadb_databases }}"
|
loop: "{{ mariadb_databases }}"
|
||||||
|
|
||||||
- name: MYSQL_USER | Manages users...
|
- name: MYSQL_USER | Manages users...
|
||||||
@@ -74,5 +75,6 @@
|
|||||||
host: "{{ item.host | default(omit) }}"
|
host: "{{ item.host | default(omit) }}"
|
||||||
host_all: "{{ item.host_all | default(omit) }}"
|
host_all: "{{ item.host_all | default(omit) }}"
|
||||||
state: present
|
state: present
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
loop: "{{ mariadb_users }}"
|
loop: "{{ mariadb_users }}"
|
||||||
no_log: "{{ not mariadb_debug_role }}"
|
no_log: "{{ not mariadb_debug_role }}"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
community.mysql.mysql_variables:
|
community.mysql.mysql_variables:
|
||||||
variable: read_only
|
variable: read_only
|
||||||
value: 'ON'
|
value: 'ON'
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
when: mariadb_slave_readonly
|
when: mariadb_slave_readonly
|
||||||
|
|
||||||
- name: TEMPLATE | Deploy slave configuration
|
- name: TEMPLATE | Deploy slave configuration
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
- name: MYSQL_REPLICATION | Get slave status
|
- name: MYSQL_REPLICATION | Get slave status
|
||||||
community.mysql.mysql_replication:
|
community.mysql.mysql_replication:
|
||||||
mode: getslave
|
mode: getslave
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: slave_status
|
register: slave_status
|
||||||
|
|
||||||
@@ -32,5 +34,6 @@
|
|||||||
- name: MYSQL_REPLICATION | Get slave status
|
- name: MYSQL_REPLICATION | Get slave status
|
||||||
community.mysql.mysql_replication:
|
community.mysql.mysql_replication:
|
||||||
mode: getslave
|
mode: getslave
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
ignore_errors: true
|
ignore_errors: true
|
||||||
register: slave_status
|
register: slave_status
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
- name: MYSQL_REPLICATION | Stop slave
|
- name: MYSQL_REPLICATION | Stop slave
|
||||||
community.mysql.mysql_replication:
|
community.mysql.mysql_replication:
|
||||||
mode: stopslave
|
mode: stopslave
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
|
||||||
- name: MYSQL_REPLICATION | Configure master host
|
- name: MYSQL_REPLICATION | Configure master host
|
||||||
community.mysql.mysql_replication:
|
community.mysql.mysql_replication:
|
||||||
@@ -11,12 +12,15 @@
|
|||||||
master_port: "{{ mariadb_replication_port }}"
|
master_port: "{{ mariadb_replication_port }}"
|
||||||
master_user: "{{ mariadb_replication_user }}"
|
master_user: "{{ mariadb_replication_user }}"
|
||||||
master_password: "{{ mariadb_replication_password }}"
|
master_password: "{{ mariadb_replication_password }}"
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
no_log: "{{ not mariadb_debug_role }}"
|
no_log: "{{ not mariadb_debug_role }}"
|
||||||
|
|
||||||
- name: MYSQL_REPLICATION | Setup replication with GTID
|
- name: MYSQL_REPLICATION | Setup replication with GTID
|
||||||
community.mysql.mysql_replication:
|
community.mysql.mysql_replication:
|
||||||
primary_use_gtid: current_pos
|
primary_use_gtid: current_pos
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
|
||||||
- name: MYSQL_REPLICATION | Start slave
|
- name: MYSQL_REPLICATION | Start slave
|
||||||
community.mysql.mysql_replication:
|
community.mysql.mysql_replication:
|
||||||
mode: startslave
|
mode: startslave
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
|||||||
@@ -44,6 +44,7 @@
|
|||||||
- name: MYSQL_VARIABLES | Get datadir
|
- name: MYSQL_VARIABLES | Get datadir
|
||||||
community.mysql.mysql_variables:
|
community.mysql.mysql_variables:
|
||||||
variable: datadir
|
variable: datadir
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
register: datadir
|
register: datadir
|
||||||
|
|
||||||
- name: SET_FACT | Get MariaDB datadir
|
- name: SET_FACT | Get MariaDB datadir
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
- name: MYSQL_REPLICATION | Stop slave
|
- name: MYSQL_REPLICATION | Stop slave
|
||||||
mysql_replication:
|
mysql_replication:
|
||||||
mode: stopslave
|
mode: stopslave
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
|
||||||
- name: MYSQL_REPLICATION | Configure master host
|
- name: MYSQL_REPLICATION | Configure master host
|
||||||
mysql_replication:
|
mysql_replication:
|
||||||
@@ -11,6 +12,7 @@
|
|||||||
master_port: "{{ mariadb_replication_port }}"
|
master_port: "{{ mariadb_replication_port }}"
|
||||||
master_user: "{{ mariadb_replication_user }}"
|
master_user: "{{ mariadb_replication_user }}"
|
||||||
master_password: "{{ mariadb_replication_password }}"
|
master_password: "{{ mariadb_replication_password }}"
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
no_log: "{{ not mariadb_debug_role }}"
|
no_log: "{{ not mariadb_debug_role }}"
|
||||||
|
|
||||||
- name: MYSQL_REPLICATION | Change master
|
- name: MYSQL_REPLICATION | Change master
|
||||||
@@ -18,8 +20,10 @@
|
|||||||
mode: changemaster
|
mode: changemaster
|
||||||
master_log_file: "{{ mariadb_master_log_file }}"
|
master_log_file: "{{ mariadb_master_log_file }}"
|
||||||
master_log_pos: "{{ mariadb_master_log_pos }}"
|
master_log_pos: "{{ mariadb_master_log_pos }}"
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined
|
when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined
|
||||||
|
|
||||||
- name: MYSQL_REPLICATION | Start slave
|
- name: MYSQL_REPLICATION | Start slave
|
||||||
mysql_replication:
|
mysql_replication:
|
||||||
mode: startslave
|
mode: startslave
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
name: ''
|
name: ''
|
||||||
host: "{{ item }}"
|
host: "{{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
loop:
|
loop:
|
||||||
- "{{ ansible_hostname }}"
|
- "{{ ansible_hostname }}"
|
||||||
- 127.0.0.1
|
- 127.0.0.1
|
||||||
@@ -15,3 +16,4 @@
|
|||||||
mysql_db:
|
mysql_db:
|
||||||
name: test
|
name: test
|
||||||
state: absent
|
state: absent
|
||||||
|
login_unix_socket: "{{ mariadb_socket }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user