From cbf36a7920786f03897bdfc3cdc126e3da195ac3 Mon Sep 17 00:00:00 2001 From: Sebastian Schwarz Date: Wed, 6 Aug 2014 11:46:54 +0200 Subject: [PATCH 1/5] Mention Debian and Ubuntu as supported platforms --- meta/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta/main.yml b/meta/main.yml index ea6aafd..c66da60 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,7 +3,7 @@ dependencies: [] galaxy_info: author: geerlingguy - description: MySQL server for RHEL/CentOS 6.x + description: MySQL server for RHEL/CentOS 6.x and Debian/Ubuntu company: "Midwestern Mac, LLC" license: "license (BSD, MIT)" min_ansible_version: 1.4 From 3a15b07608484522a1e72f287c3378d13c54991b Mon Sep 17 00:00:00 2001 From: Sebastian Schwarz Date: Wed, 6 Aug 2014 11:47:59 +0200 Subject: [PATCH 2/5] Allow creation of databases and users Inspired by the Ansibles.mysql role. --- README.md | 17 +++++++++++++++++ defaults/main.yml | 4 ++++ tasks/main.yml | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/README.md b/README.md index 1d9a651..392569f 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,14 @@ The home directory inside which Python MySQL settings will be stored, which Ansi The MySQL root user account password. + mysql_databases: [] + +The MySQL databases to create. A database has the values `name`, `encoding` (defaults to `utf8`) and `collation` (defaults to `utf8_general_ci`). The formats of these are the same as in the `mysql_db` module. + + mysql_users: [] + +The MySQL users and their privileges. A user has the values `name`, `host` (defaults to `localhost`), `password` and `priv` (defaults to `*.*:USAGE`). The formats of these are the same as in the `mysql_user` module. + mysql_packages: - mysql - mysql-server @@ -59,6 +67,15 @@ None. *Inside `vars/main.yml`*: mysql_root_password: super-secure-password + mysql_databases: + - name: example_db + encoding: latin1 + collation: latin1_general_ci + mysql_users: + - name: example_user + host: "%" + password: similarly-secure-password + priv: "example_db.*:ALL" ## License diff --git a/defaults/main.yml b/defaults/main.yml index 29c09b9..1db9880 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -42,3 +42,7 @@ mysql_innodb_lock_wait_timeout: 50 # mysqldump settings mysql_mysqldump_max_allowed_packet: "64M" + +# databases and users settings +mysql_databases: [] +mysql_users: [] diff --git a/tasks/main.yml b/tasks/main.yml index 8b9850a..c69147a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -70,3 +70,20 @@ mysql_db: > name="test" state=absent + +- name: Ensure MySQL databases are present. + mysql_db: > + name="{{ item.name }}" + collation="{{ item.collation | default('utf8_general_ci') }}" + encoding="{{ item.encoding | default('utf8') }}" + state=present + with_items: mysql_databases + +- name: Ensure MySQL users are present. + mysql_user: > + name="{{ item.name }}" + host="{{ item.host | default('localhost') }}" + password="{{ item.password }}" + priv="{{ item.priv | default('*.*:USAGE') }}" + state=present + with_items: mysql_users From 64e337194c7e2efc9dc80ba67ee75a824d650caa Mon Sep 17 00:00:00 2001 From: Sebastian Schwarz Date: Thu, 7 Aug 2014 12:41:33 +0200 Subject: [PATCH 3/5] Make MySQL root username configurable While this doesn't seem to make sense on first glance it is useful for systems which were screwed with Parallels Plesk, which renames the MySQL root user to "admin". This change allowes this role to be used while the server is transitioning from Plesk to Ansible. --- defaults/main.yml | 1 + templates/python-my.cnf.j2 | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 1db9880..7f20304 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,6 @@ --- mysql_user_home: /root +mysql_root_username: root mysql_root_password: root # Pass in a comma-separated list of repos to use (e.g. "remi,epel"). Used only diff --git a/templates/python-my.cnf.j2 b/templates/python-my.cnf.j2 index b013aa3..43de06a 100644 --- a/templates/python-my.cnf.j2 +++ b/templates/python-my.cnf.j2 @@ -1,3 +1,3 @@ [client] -user=root -password={{ mysql_root_password }} \ No newline at end of file +user={{ mysql_root_username }} +password={{ mysql_root_password }} From c8368995363950374601e54e34be8e88b51ee86b Mon Sep 17 00:00:00 2001 From: Sebastian Schwarz Date: Thu, 7 Aug 2014 12:50:14 +0200 Subject: [PATCH 4/5] Make error logging configurable --- README.md | 5 +++++ defaults/main.yml | 4 ++++ templates/my.cnf.j2 | 8 +++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 392569f..212ab71 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,11 @@ The MySQL users and their privileges. A user has the values `name`, `host` (defa Default MySQL connection configuration. + mysql_log_error: /var/log/mysqld.log + mysql_syslog_tag: mysqld + +MySQL logging configuration. Setting `mysql_log_error` to `syslog` will make MySQL log to syslog using the `mysql_syslog_tag`. + mysql_key_buffer_size: "256M" mysql_max_allowed_packet: "1M" mysql_table_open_cache: "256" diff --git a/defaults/main.yml b/defaults/main.yml index 7f20304..d8a19e6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -44,6 +44,10 @@ mysql_innodb_lock_wait_timeout: 50 # mysqldump settings mysql_mysqldump_max_allowed_packet: "64M" +# mysqld_safe setting +mysql_log_error: /var/log/mysqld.log +mysql_syslog_tag: mysqld + # databases and users settings mysql_databases: [] mysql_users: [] diff --git a/templates/my.cnf.j2 b/templates/my.cnf.j2 index 13c387d..245cbc5 100644 --- a/templates/my.cnf.j2 +++ b/templates/my.cnf.j2 @@ -52,5 +52,11 @@ quick max_allowed_packet = {{ mysql_mysqldump_max_allowed_packet }} [mysqld_safe] -log-error = /var/log/mysqld.log +{% if mysql_log_error == 'syslog' %} +syslog +syslog-tag = {{ mysql_syslog_tag }} +{% else %} +skip-syslog +log-error = {{ mysql_log_error }} +{% endif %} pid-file = /var/run/mysqld/mysqld.pid From ff924e6f19a186f290cd03f6a35cb2d498466ed7 Mon Sep 17 00:00:00 2001 From: Sebastian Schwarz Date: Thu, 7 Aug 2014 12:55:56 +0200 Subject: [PATCH 5/5] Also adjust port and socket of the MySQL client --- templates/my.cnf.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/my.cnf.j2 b/templates/my.cnf.j2 index 245cbc5..ee0ac85 100644 --- a/templates/my.cnf.j2 +++ b/templates/my.cnf.j2 @@ -1,7 +1,7 @@ [client] #password = your_password -port = 3306 -socket = /var/lib/mysql/mysql.sock +port = {{ mysql_port }} +socket = {{ mysql_socket }} [mysqld] port = {{ mysql_port }}