Skip to content

Commit d098cd9

Browse files
committed
Merge branch 'master' of github.com:geerlingguy/ansible-role-mysql
2 parents d733583 + 04d1000 commit d098cd9

File tree

7 files changed

+61
-7
lines changed

7 files changed

+61
-7
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before_install:
99
- sudo apt-get update -qq
1010

1111
# Remove MySQL. Completely and totally.
12-
- sudo apt-get remove --purge -s 'mysql*'
12+
- sudo apt-get remove --purge 'mysql*'
1313
- sudo apt-get autoremove
1414
- sudo apt-get autoclean
1515
- sudo rm -rf /var/lib/mysql

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ The home directory inside which Python MySQL settings will be stored, which Ansi
2020

2121
The MySQL root user account password.
2222

23+
mysql_databases: []
24+
25+
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.
26+
27+
mysql_users: []
28+
29+
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.
30+
2331
mysql_packages:
2432
- mysql
2533
- mysql-server
@@ -37,6 +45,11 @@ The MySQL root user account password.
3745

3846
Default MySQL connection configuration.
3947

48+
mysql_log_error: /var/log/mysqld.log
49+
mysql_syslog_tag: mysqld
50+
51+
MySQL logging configuration. Setting `mysql_log_error` to `syslog` will make MySQL log to syslog using the `mysql_syslog_tag`.
52+
4053
mysql_key_buffer_size: "256M"
4154
mysql_max_allowed_packet: "1M"
4255
mysql_table_open_cache: "256"
@@ -59,6 +72,15 @@ None.
5972
*Inside `vars/main.yml`*:
6073

6174
mysql_root_password: super-secure-password
75+
mysql_databases:
76+
- name: example_db
77+
encoding: latin1
78+
collation: latin1_general_ci
79+
mysql_users:
80+
- name: example_user
81+
host: "%"
82+
password: similarly-secure-password
83+
priv: "example_db.*:ALL"
6284

6385
## License
6486

defaults/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
mysql_user_home: /root
3+
mysql_root_username: root
34
mysql_root_password: root
45

56
# Pass in a comma-separated list of repos to use (e.g. "remi,epel"). Used only
@@ -42,3 +43,11 @@ mysql_innodb_lock_wait_timeout: 50
4243

4344
# mysqldump settings
4445
mysql_mysqldump_max_allowed_packet: "64M"
46+
47+
# mysqld_safe setting
48+
mysql_log_error: /var/log/mysqld.log
49+
mysql_syslog_tag: mysqld
50+
51+
# databases and users settings
52+
mysql_databases: []
53+
mysql_users: []

meta/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ dependencies: []
33

44
galaxy_info:
55
author: geerlingguy
6-
description: MySQL server for RHEL/CentOS 6.x
6+
description: MySQL server for RHEL/CentOS 6.x and Debian/Ubuntu
77
company: "Midwestern Mac, LLC"
88
license: "license (BSD, MIT)"
99
min_ansible_version: 1.4

tasks/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,20 @@
7070
mysql_db: >
7171
name="test"
7272
state=absent
73+
74+
- name: Ensure MySQL databases are present.
75+
mysql_db: >
76+
name="{{ item.name }}"
77+
collation="{{ item.collation | default('utf8_general_ci') }}"
78+
encoding="{{ item.encoding | default('utf8') }}"
79+
state=present
80+
with_items: mysql_databases
81+
82+
- name: Ensure MySQL users are present.
83+
mysql_user: >
84+
name="{{ item.name }}"
85+
host="{{ item.host | default('localhost') }}"
86+
password="{{ item.password }}"
87+
priv="{{ item.priv | default('*.*:USAGE') }}"
88+
state=present
89+
with_items: mysql_users

templates/my.cnf.j2

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[client]
22
#password = your_password
3-
port = 3306
4-
socket = /var/lib/mysql/mysql.sock
3+
port = {{ mysql_port }}
4+
socket = {{ mysql_socket }}
55

66
[mysqld]
77
port = {{ mysql_port }}
@@ -52,5 +52,11 @@ quick
5252
max_allowed_packet = {{ mysql_mysqldump_max_allowed_packet }}
5353

5454
[mysqld_safe]
55-
log-error = /var/log/mysqld.log
55+
{% if mysql_log_error == 'syslog' %}
56+
syslog
57+
syslog-tag = {{ mysql_syslog_tag }}
58+
{% else %}
59+
skip-syslog
60+
log-error = {{ mysql_log_error }}
61+
{% endif %}
5662
pid-file = /var/run/mysqld/mysqld.pid

templates/python-my.cnf.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[client]
2-
user=root
3-
password={{ mysql_root_password }}
2+
user={{ mysql_root_username }}
3+
password={{ mysql_root_password }}

0 commit comments

Comments
 (0)