Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Custom Data Directory #518

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
hosts: all
become: true

vars:
mysql_datadir: "/opt/mysql"

roles:
- role: geerlingguy.mysql

Expand Down
12 changes: 12 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@
- mysql_log_error | default(false)
tags: ['skip_ansible_galaxy']

- name: Initialize mysql when mysql_datadir is customized (MySQL)
ansible.builtin.command: mysqld --initialize-insecure --user=mysql --datadir={{ mysql_datadir }}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could interfere with later initialization, though, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which later initialization? I can't get molecule to run the rockylinux on my m1 mac, but the ubuntu2204 and 2004, both seem to pass the tests, when specifying an alternate data directory for both mysql and mariadb.

I am trying to modify the github actions to run the additional tests (I believe that is the way to do it?) I can't find a way to have different playbooks in molecule that tear down everything between playbooks.

Copy link

@widhalmt widhalmt Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still depends. @geerlingguy do you want to have an extra molecule scenario for a moved directory or should it be part of default? I made a PR to the PR of @misilot and I'm ready to change as you want it to have.

I can help you @misilot . But in short: If you want two different playbooks, you make two scenarios in Molecule. Copy the default folder and change converge.yml like you want the other playbook to be

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I am working on the logic to check the version number instead of looking for package names, since debian uses mysql in the package name, but is really mariadb, the logic I have doesn't work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I fixed the logic, and they all seem to run locally with molecule. I also added in @widhalmt change to this PR.

args:
creates: "{{ mysql_datadir }}/mysql"
when: mysql_datadir != "/var/lib/mysql" and ('5.7.' in mysql_cli_version.stdout or '8.0.' in mysql_cli_version.stdout)

- name: Initialize mysql when mysql_datadir is customized (MariaDB)
ansible.builtin.command: mysql_install_db
args:
creates: "{{ mysql_datadir }}/mysql"
when: mysql_datadir != "/var/lib/mysql" and ('5.7.' not in mysql_cli_version.stdout or '8.0.' not in mysql_cli_version.stdout)

- name: Ensure MySQL is started and enabled on boot.
ansible.builtin.service:
name: "{{ mysql_daemon }}"
Expand Down