Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
hosts: all
# become: true

vars:
mysql_config_include_files:
- src: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}/molecule/default/templates/override.cnf"

roles:
- role: geerlingguy.mysql
- role: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') }}"

post_tasks:
- name: Make sure we can connect to MySQL via Unix socket.
Expand Down
2 changes: 2 additions & 0 deletions molecule/default/templates/override.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mysqld]
innodb_page_size = 32K
24 changes: 21 additions & 3 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
- name: Get MySQL version
block:
- name: Run mysql --version
ansible.builtin.command: '{{ mysql_daemon }} --version'
ansible.builtin.command: "{{ mysql_daemon }} --version"
register: mysql_cli_version
changed_when: false
check_mode: false

- name: Set MariaDB flag.
ansible.builtin.set_fact:
mysql_is_mariadb: "{{ 'MariaDB' in mysql_cli_version.stdout }}"

- name: Extract MySQL version
ansible.builtin.set_fact:
mysql_cli_version: >-
Expand Down Expand Up @@ -42,14 +46,20 @@
with_items: "{{ mysql_config_include_files }}"
notify: restart mysql

- name: Check if datadir exists.
ansible.builtin.stat:
path: "{{ mysql_datadir }}"
register: mysql_datadir_stat

- name: Create datadir if it does not exist
ansible.builtin.file:
path: "{{ mysql_datadir }}"
state: directory
owner: mysql
group: mysql
mode: 0755
mode: "0750"
setype: mysqld_db_t
when: not mysql_datadir_stat.stat.exists

- name: Ensure error log directory exists
ansible.builtin.file:
Expand All @@ -62,6 +72,14 @@
- mysql_log_error | default('') | length > 0
- mysql_log_error != 'syslog'

- name: Initialize MySQL datadir.
ansible.builtin.command: >-
{{ 'mariadb-install-db --user=mysql --datadir=' + mysql_datadir
if mysql_is_mariadb | default(false)
else 'mysqld --initialize-insecure --user=mysql' }}
when: mysql_initialize_datadir | default(false)
changed_when: true

- name: Ensure slow query log file exists and has correct permissions
ansible.builtin.file:
path: "{{ mysql_slow_query_log_file }}"
Expand All @@ -86,7 +104,7 @@
- mysql_log | default('') | length > 0
- mysql_log_error | default('') | length > 0
- mysql_log_error != 'syslog'
tags: ['skip_ansible_galaxy']
tags: ["skip_ansible_galaxy"]

- name: Ensure MySQL is started and enabled on boot.
ansible.builtin.service:
Expand Down
23 changes: 14 additions & 9 deletions tasks/setup-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@
register: deb_mysql_install_packages

# Because Ubuntu starts MySQL as part of the install process, we need to stop
# mysql and remove the logfiles in case the user set a custom log file size.
# mysql and remove the logfiles in case the user set a custom log file size,
# same holds for ibdata, as innodb settings might conflict with the default ibdata file created.
- name: Ensure MySQL is stopped after initial install.
ansible.builtin.service:
name: "{{ mysql_daemon }}"
state: stopped
when: not mysql_installed.stat.exists

- name: Delete innodb log files created by apt package after initial install.
- name: Remove MySQL datadir to allow clean reinitialization with custom InnoDB settings.
ansible.builtin.file:
path: "{{ mysql_datadir }}/{{ item }}"
path: "{{ mysql_datadir }}"
state: absent
with_items:
- ib_logfile0
- ib_logfile1
when: >
not mysql_installed.stat.exists
and ansible_facts.distribution_major_version | int < 12
when:
- not mysql_installed.stat.exists
- ansible_facts.os_family == 'Debian'

- name: Set flag to initialize MySQL datadir after config is written.
ansible.builtin.set_fact:
mysql_initialize_datadir: true
when:
- not mysql_installed.stat.exists
- ansible_facts.os_family == 'Debian'
Loading