diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2019-10-01 22:02:32 -0400 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2019-10-01 22:02:32 -0400 |
| commit | acc2965258fb85aca1faf92ea8b65a25f964c8fa (patch) | |
| tree | 22e89f849a73b8c4e0fe214e8b610d1e36d6bd84 | |
| download | alpine-mysql-acc2965258fb85aca1faf92ea8b65a25f964c8fa.tar.gz alpine-mysql-acc2965258fb85aca1faf92ea8b65a25f964c8fa.tar.xz | |
Initial
| -rw-r--r-- | defaults/main.yml | 15 | ||||
| -rw-r--r-- | readme.md | 5 | ||||
| -rw-r--r-- | tasks/main.yml | 41 | ||||
| -rw-r--r-- | templates/my.cnf.j2 | 3 | ||||
| -rw-r--r-- | templates/run.j2 | 7 | ||||
| -rw-r--r-- | templates/user-my.cnf.j2 | 15 |
6 files changed, 86 insertions, 0 deletions
diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..53e1ee9 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,15 @@ + +# mariadb_root_passwd: 'change me!' + +mariadb_opts: | + bind-address = 127.0.0.1 + port = 3306 + datadir = /var/mysql + innodb_buffer_pool_size = 128M + max_allowed_packet = 16M + + # Disabling symbolic-links is recommended to prevent assorted security risks + symbolic-links=0 + + +runit_svc_name: mysql diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..cab4860 --- /dev/null +++ b/readme.md @@ -0,0 +1,5 @@ +# MySQL / Mariadb Role for Alpine Linux + + +Somewhat similar to the Postgresql role I created. Should be pretty +easy to adapt to other distributions if you wish. diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..e739bc6 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,41 @@ +- name: Install Mariadb + apk: + name: + - mariadb + - mariadb-client + update_cache: yes +- name: Install my.cnf for MySQL + template: + src: my.cnf.j2 + dest: /etc/my.cnf + mode: '444' +- name: Install Runit service directory + file: + state: directory + path: '/etc/sv/{{runit_svc_name}}' + mode: '0755' +- name: Install Runit service command + template: + src: run.j2 + dest: '/etc/sv/{{runit_svc_name}}/run' + mode: '755' +- name: Install supervise symlink + file: + state: link + force: yes + src: '/run/supervise.{{runit_svc_name}}' + dest: '/etc/sv/{{runit_svc_name}}/supervise' + follow: false +- name: Enable Runit service + file: + state: link + force: yes + src: '/etc/sv/{{runit_svc_name}}' + dest: '/var/service/{{runit_svc_name}}' + follow: false +- name: Write my.cnf for 'root' + template: + src: 'user-my.cnf.j2' + dest: '/root/.my.cnf' + mode: '0400' + when: mariadb_root_passwd is defined diff --git a/templates/my.cnf.j2 b/templates/my.cnf.j2 new file mode 100644 index 0000000..cd6778f --- /dev/null +++ b/templates/my.cnf.j2 @@ -0,0 +1,3 @@ +[client-server] +[mysqld] +{{mariadb_opts}} diff --git a/templates/run.j2 b/templates/run.j2 new file mode 100644 index 0000000..f962193 --- /dev/null +++ b/templates/run.j2 @@ -0,0 +1,7 @@ +#!/bin/sh +mkdir -p /run/mysqld && chown mysql:mysql /run/mysqld +datadir="$(sed -rne's/^datadir ?= ?//p' /etc/my.cnf)" +if ! [ -d "$datadir" ] ; then + mysql_install_db --user=mysql +fi +exec chpst -u mysql:mysql mysqld diff --git a/templates/user-my.cnf.j2 b/templates/user-my.cnf.j2 new file mode 100644 index 0000000..1a952e7 --- /dev/null +++ b/templates/user-my.cnf.j2 @@ -0,0 +1,15 @@ +[client] +user=root +password="{{mariadb_root_passwd}}" + +[mysql] +user=root +password="{{mariadb_root_passwd}}" + +[mysqldump] +user=root +password="{{mariadb_root_passwd}}" + +[mysqldiff] +user=root +password="{{mariadb_root_passwd}}" |
