mirror of
https://github.com/HanXHX/ansible-mysql.git
synced 2026-02-26 10:22:09 +07:00
🔨 Add molecule
This commit is contained in:
committed by
Emilien M
parent
98237aab2f
commit
9a79dd8d63
19
molecule/_shared/Dockerfile.j2
Normal file
19
molecule/_shared/Dockerfile.j2
Normal file
@@ -0,0 +1,19 @@
|
||||
# Molecule managed
|
||||
|
||||
{% if item.registry is defined %}
|
||||
FROM {{ item.registry.url }}/{{ item.image }}
|
||||
{% else %}
|
||||
FROM {{ item.image }}
|
||||
{% endif %}
|
||||
|
||||
{% if item.env is defined %}
|
||||
{% for var, value in item.env.items() %}
|
||||
{% if value %}
|
||||
ENV {{ var }} {{ value }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y python3 sudo bash ca-certificates iproute2 python-apt-common \
|
||||
&& apt-get clean
|
||||
38
molecule/_shared/base.yml
Normal file
38
molecule/_shared/base.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
|
||||
scenario:
|
||||
test_sequence:
|
||||
- dependency
|
||||
- syntax
|
||||
- create
|
||||
- prepare
|
||||
- converge
|
||||
- idempotence
|
||||
- verify
|
||||
- destroy
|
||||
driver:
|
||||
name: docker
|
||||
role_name_check: 1
|
||||
provisioner:
|
||||
name: ansible
|
||||
config_options:
|
||||
defaults:
|
||||
deprecation_warnings: false
|
||||
callback_whitelist: timer,profile_tasks
|
||||
fact_caching: jsonfile
|
||||
fact_caching_connection: ./cache
|
||||
forks: 100
|
||||
connection:
|
||||
pipelining: true
|
||||
playbooks:
|
||||
converge: ../_shared/converge.yml
|
||||
prepare: ../_shared/prepare.yml
|
||||
verify: ../_shared/verify.yml
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
is_dev: true
|
||||
links:
|
||||
group_vars: ../_shared/inventory/group_vars/
|
||||
verifier:
|
||||
name: ansible
|
||||
34
molecule/_shared/converge.yml
Normal file
34
molecule/_shared/converge.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
|
||||
# Note: master must be converged first
|
||||
- name: Converge master
|
||||
hosts: master
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Include role
|
||||
ansible.builtin.include_role:
|
||||
name: "hanxhx.mysql"
|
||||
|
||||
- name: COPY | Deploy first dump
|
||||
ansible.builtin.copy:
|
||||
src: files/import1.sql
|
||||
dest: /tmp/import1.sql
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: root
|
||||
|
||||
- name: MYSQL_DB | Import first dump
|
||||
community.mysql.mysql_db:
|
||||
name: "{{ item }}"
|
||||
state: import
|
||||
target: /tmp/import1.sql
|
||||
login_unix_socket: "/run/mysqld/mysqld.sock"
|
||||
loop: "{{ mariadb_databases }}"
|
||||
|
||||
- name: Converge slave
|
||||
hosts: slave
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Include role
|
||||
ansible.builtin.include_role:
|
||||
name: "hanxhx.mysql"
|
||||
11
molecule/_shared/files/import1.sql
Normal file
11
molecule/_shared/files/import1.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS `user` (
|
||||
`id` mediumint(8) unsigned NOT NULL auto_increment,
|
||||
`email` varchar(255) default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) AUTO_INCREMENT=1;
|
||||
|
||||
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (1,"tellus.Suspendisse.sed@gravida.edu"),(2,"Nulla.tempor@nonsapienmolestie.edu"),(3,"a.odio@eu.org"),(4,"adipiscing.ligula.Aenean@augueeu.com"),(5,"id.enim.Curabitur@dictumeleifendnunc.org"),(6,"est.mollis.non@laoreetlectus.net"),(7,"fringilla@mollisduiin.edu"),(8,"amet@lacusQuisquepurus.co.uk"),(9,"elementum.dui@pellentesque.org"),(10,"dictum.eu.placerat@dolorQuisque.com");
|
||||
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (11,"vitae.dolor@rutrumnon.net"),(12,"semper@mattis.co.uk"),(13,"tincidunt.congue.turpis@placerateget.co.uk"),(14,"ornare.sagittis.felis@vitaesemper.ca"),(15,"luctus@sapien.ca"),(16,"tellus.id.nunc@necluctus.net"),(17,"quis.pede.Praesent@posuereenim.co.uk"),(18,"quis@metusvitaevelit.com"),(19,"in.sodales@velarcu.net"),(20,"et@sagittisplacerat.net");
|
||||
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (21,"aliquam@atpretium.co.uk"),(22,"cursus@sapienmolestie.edu"),(23,"ornare.Fusce@pede.ca"),(24,"at@estac.co.uk"),(25,"sed@risusodioauctor.ca"),(26,"sit.amet.consectetuer@necorciDonec.com"),(27,"Nulla@infaucibus.co.uk"),(28,"tempus.scelerisque@utlacusNulla.com"),(29,"pellentesque.a@nostraper.com"),(30,"libero.et.tristique@Nunclaoreet.co.uk");
|
||||
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (31,"dolor.sit.amet@Donecelementum.net"),(32,"ornare@massanonante.ca"),(33,"quam.elementum@semper.net"),(34,"Duis.ac.arcu@Integermollis.com"),(35,"magna.Sed.eu@magnaPraesent.co.uk"),(36,"Mauris.eu.turpis@mattis.ca"),(37,"ornare.facilisis.eget@urna.net"),(38,"Sed.diam.lorem@fringilla.co.uk"),(39,"pellentesque.Sed.dictum@Donec.edu"),(40,"faucibus.Morbi@nuncid.com");
|
||||
INSERT IGNORE INTO `user` (`id`,`email`) VALUES (41,"ullamcorper@at.co.uk"),(42,"nec.ante.blandit@utcursus.edu"),(43,"diam.vel.arcu@egestasFuscealiquet.com"),(44,"ridiculus@musAeneaneget.com"),(45,"ad@turpisvitaepurus.ca"),(46,"ultrices.posuere.cubilia@purusMaecenas.net"),(47,"luctus@libero.org"),(48,"mi@elitNulla.com"),(49,"elementum@ipsumdolorsit.edu"),(50,"orci@Donec.co.uk");
|
||||
8
molecule/_shared/inventory/group_vars/all.yml
Normal file
8
molecule/_shared/inventory/group_vars/all.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
|
||||
mariadb_bind_address: '0.0.0.0'
|
||||
mariadb_extra_configuration:
|
||||
innodb_commit_concurrency: 0
|
||||
mariadb_install_xtrabackup_package: true
|
||||
mariadb_slow_query_log_enabled: true
|
||||
mariadb_debug_role: true
|
||||
4
molecule/_shared/inventory/group_vars/galera.yml
Normal file
4
molecule/_shared/inventory/group_vars/galera.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
mariadb_use_galera: true
|
||||
mariadb_galera_members: "{{ groups['galera'] }}"
|
||||
19
molecule/_shared/inventory/group_vars/master.yml
Normal file
19
molecule/_shared/inventory/group_vars/master.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
|
||||
# Master durability
|
||||
mariadb_sync_binlog: '1'
|
||||
mariadb_innodb_flush_log_at_trx_commit: '1'
|
||||
|
||||
mariadb_databases:
|
||||
- 'testrepl'
|
||||
- 'norepl'
|
||||
|
||||
mariadb_users:
|
||||
- name: 'replication'
|
||||
password: '1a2b3c'
|
||||
priv: '*.*:REPLICATION SLAVE'
|
||||
host: '%'
|
||||
mariadb_replication_master: true
|
||||
mariadb_replication_slave: false
|
||||
|
||||
# vim: set ft=yaml :
|
||||
11
molecule/_shared/inventory/group_vars/slave.yml
Normal file
11
molecule/_shared/inventory/group_vars/slave.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
|
||||
mariadb_replication_master: false
|
||||
mariadb_replication_slave: true
|
||||
mariadb_replication_user: 'replication'
|
||||
mariadb_replication_password: '1a2b3c'
|
||||
mariadb_slave_ignore_db: ['norepl']
|
||||
mariadb_slave_import_from: "{{ groups['master'][0] }}"
|
||||
mariadb_replication_host: "{{ groups['master'][0] }}"
|
||||
|
||||
# vim: set ft=yaml :
|
||||
21
molecule/_shared/prepare.yml
Normal file
21
molecule/_shared/prepare.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
|
||||
- name: Prepare hosts
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: APT | Install some packages
|
||||
ansible.builtin.apt:
|
||||
name: "{{ p }}"
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
vars:
|
||||
p: ['ca-certificates', 'curl', 'rsync', 'rsyslog', 'ssh', 'strace', 'vim']
|
||||
|
||||
- name: SERVICE | Ensure daemon are started
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
loop:
|
||||
- rsyslog
|
||||
- ssh
|
||||
32
molecule/_shared/verify.yml
Normal file
32
molecule/_shared/verify.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
|
||||
- name: Verify slave
|
||||
hosts: slave
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: MYSQL_REPLICATION | Get slave infos
|
||||
community.mysql.mysql_replication:
|
||||
mode: getreplica
|
||||
register: slave
|
||||
|
||||
- name: ASSERT | If slave threads are not running
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- slave.Slave_IO_Running == 'Yes'
|
||||
- slave.Slave_SQL_Running == 'Yes'
|
||||
fail_msg: "Slave issue, please check"
|
||||
success_msg: "Slave is running"
|
||||
|
||||
- name: Check replication data
|
||||
community.mysql.mysql_query:
|
||||
login_db: testrepl
|
||||
query: 'SELECT COUNT(*) AS c FROM user'
|
||||
login_unix_socket: /run/mysqld/mysqld.sock
|
||||
register: result
|
||||
|
||||
- name: ASSERT | Check replication data
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- result.query_result.0.0.c == 50
|
||||
fail_msg: "Replication data is not correct"
|
||||
success_msg: "Replication data is correct"
|
||||
46
molecule/debian12_master_slave/molecule.yml
Normal file
46
molecule/debian12_master_slave/molecule.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
---
|
||||
|
||||
platforms:
|
||||
- name: debian12-master1
|
||||
image: dokken/debian-12
|
||||
command: /lib/systemd/systemd
|
||||
dockerfile: ../_shared/Dockerfile.j2
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
privileged: true
|
||||
networks:
|
||||
- name: "00-molecule-d12-ms"
|
||||
ipv4_address: '172.16.50.1'
|
||||
docker_networks:
|
||||
- name: "00-molecule-d12-ms"
|
||||
ipam_config:
|
||||
- subnet: "172.16.50.0/24"
|
||||
gateway: "172.16.50.254"
|
||||
groups:
|
||||
- master
|
||||
|
||||
- name: debian12-slave1
|
||||
image: dokken/debian-12
|
||||
command: /lib/systemd/systemd
|
||||
dockerfile: ../_shared/Dockerfile.j2
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
privileged: true
|
||||
networks:
|
||||
- name: "00-molecule-d12-ms"
|
||||
ipv4_address: '172.16.50.2'
|
||||
groups:
|
||||
- slave
|
||||
|
||||
provisioner:
|
||||
inventory:
|
||||
host_vars: ~
|
||||
group_vars:
|
||||
master: ~
|
||||
slave: ~
|
||||
Reference in New Issue
Block a user