Skip to content

Commit 2c8c807

Browse files
authored
Merge pull request geerlingguy#135 from JorisVanEijden/132-overridable-variables
Provide overridable OS-specific defaults.
2 parents fddbcb4 + e3cd60c commit 2c8c807

File tree

7 files changed

+101
-47
lines changed

7 files changed

+101
-47
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ Whether to force update the MySQL root user's password. By default, this role wi
3535

3636
Whether MySQL should be enabled on startup.
3737

38+
mysql_config_file: *default value depends on OS*
39+
mysql_config_include_dir: *default value depends on OS*
40+
41+
The main my.cnf configuration file and include directory.
42+
3843
overwrite_global_mycnf: yes
3944

4045
Whether the global my.cnf should be overwritten each time this role is run. Setting this to `no` tells Ansible to only create the `my.cnf` file if it doesn't exist. This should be left at its default value (`yes`) if you'd like to use this role's variables to configure MySQL.
@@ -64,17 +69,19 @@ The MySQL users and their privileges. A user has the values `name`, `host` (defa
6469
mysql_port: "3306"
6570
mysql_bind_address: '0.0.0.0'
6671
mysql_datadir: /var/lib/mysql
72+
mysql_socket: *default value depends on OS*
73+
mysql_pid_file: *default value depends on OS*
6774

6875
Default MySQL connection configuration.
6976

7077
mysql_log: ""
71-
mysql_log_error: /var/log/mysqld.log
72-
mysql_syslog_tag: mysqld
78+
mysql_log_error: *default value depends on OS*
79+
mysql_syslog_tag: *default value depends on OS*
7380

7481
MySQL logging configuration. Setting `mysql_log` (the general query log) or `mysql_log_error` to `syslog` will make MySQL log to syslog using the `mysql_syslog_tag`.
7582

7683
mysql_slow_query_log_enabled: no
77-
mysql_slow_query_log_file: /var/log/mysql-slow.log
84+
mysql_slow_query_log_file: *default value depends on OS*
7885
mysql_slow_query_time: 2
7986

8087
Slow query log settings. Note that the log file will be created by this role, but if you're running on a server with SELinux or AppArmor, you may need to add this path to the allowed paths for MySQL, or disable the mysql profile. For example, on Debian/Ubuntu, you can run `sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/usr.sbin.mysqld && sudo service apparmor restart`.

defaults/main.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ mysql_enabled_on_startup: yes
1111
# update my.cnf. each time role is run? yes | no
1212
overwrite_global_mycnf: yes
1313

14+
# The following variables have a default value depending on operating system.
15+
# mysql_config_file: /etc/my.cnf
16+
# mysql_config_include_dir: /etc/my.cnf.d
17+
1418
# Pass in a comma-separated list of repos to use (e.g. "remi,epel"). Used only
1519
# for RedHat systems (and derivatives).
1620
mysql_enablerepo: ""
@@ -25,14 +29,17 @@ mysql_enablerepo: ""
2529
# MySQL connection settings.
2630
mysql_port: "3306"
2731
mysql_bind_address: '0.0.0.0'
28-
mysql_datadir: /var/lib/mysql
29-
mysql_pid_file: /var/run/mysqld/mysqld.pid
3032
mysql_skip_name_resolve: no
33+
mysql_datadir: /var/lib/mysql
34+
# The following variables have a default value depending on operating system.
35+
# mysql_pid_file: /var/run/mysqld/mysqld.pid
36+
# mysql_socket: /var/lib/mysql/mysql.sock
3137

3238
# Slow query log settings.
3339
mysql_slow_query_log_enabled: no
34-
mysql_slow_query_log_file: /var/log/mysql-slow.log
3540
mysql_slow_query_time: "2"
41+
# The following variable has a default value depending on operating system.
42+
# mysql_slow_query_log_file: /var/log/mysql-slow.log
3643

3744
# Memory settings (default values optimized ~512MB RAM).
3845
mysql_key_buffer_size: "256M"
@@ -72,8 +79,9 @@ mysql_mysqldump_max_allowed_packet: "64M"
7279

7380
# Logging settings.
7481
mysql_log: ""
75-
mysql_log_error: /var/log/mysql.err
76-
mysql_syslog_tag: mysql
82+
# The following variables have a default value depending on operating system.
83+
# mysql_log_error: /var/log/mysql.err
84+
# mysql_syslog_tag: mysql
7785

7886
mysql_config_include_files: []
7987
# - src: path/relative/to/playbook/file.cnf

tasks/main.yml

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,6 @@
11
---
22
# Variable configuration.
3-
- name: Include OS-specific variables.
4-
include_vars: "{{ ansible_os_family }}.yml"
5-
when: ansible_os_family != "RedHat"
6-
7-
- name: Include OS-specific variables (RedHat).
8-
include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
9-
when: ansible_os_family == "RedHat"
10-
11-
- name: Define mysql_packages.
12-
set_fact:
13-
mysql_packages: "{{ __mysql_packages | list }}"
14-
when: mysql_packages is not defined
15-
16-
- name: Define mysql_daemon.
17-
set_fact:
18-
mysql_daemon: "{{ __mysql_daemon }}"
19-
when: mysql_daemon is not defined
20-
21-
- name: Define mysql_slow_query_log_file.
22-
set_fact:
23-
mysql_slow_query_log_file: "{{ __mysql_slow_query_log_file }}"
24-
when: mysql_slow_query_log_file is not defined
25-
26-
- name: Define mysql_supports_innodb_large_prefix.
27-
set_fact:
28-
mysql_supports_innodb_large_prefix: "{{ __mysql_supports_innodb_large_prefix }}"
29-
when: mysql_supports_innodb_large_prefix is not defined
3+
- include: variables.yml
304

315
# Setup/install tasks.
326
- include: setup-RedHat.yml

tasks/variables.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
# Variable configuration.
3+
- name: Include OS-specific variables.
4+
include_vars: "{{ ansible_os_family }}.yml"
5+
when: ansible_os_family != "RedHat"
6+
7+
- name: Include OS-specific variables (RedHat).
8+
include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
9+
when: ansible_os_family == "RedHat"
10+
11+
- name: Define mysql_packages.
12+
set_fact:
13+
mysql_packages: "{{ __mysql_packages | list }}"
14+
when: mysql_packages is not defined
15+
16+
- name: Define mysql_daemon.
17+
set_fact:
18+
mysql_daemon: "{{ __mysql_daemon }}"
19+
when: mysql_daemon is not defined
20+
21+
- name: Define mysql_slow_query_log_file.
22+
set_fact:
23+
mysql_slow_query_log_file: "{{ __mysql_slow_query_log_file }}"
24+
when: mysql_slow_query_log_file is not defined
25+
26+
- name: Define mysql_log_error.
27+
set_fact:
28+
mysql_log_error: "{{ __mysql_log_error }}"
29+
when: mysql_log_error is not defined
30+
31+
- name: Define mysql_syslog_tag.
32+
set_fact:
33+
mysql_syslog_tag: "{{ __mysql_syslog_tag }}"
34+
when: mysql_syslog_tag is not defined
35+
36+
- name: Define mysql_pid_file.
37+
set_fact:
38+
mysql_pid_file: "{{ __mysql_pid_file }}"
39+
when: mysql_pid_file is not defined
40+
41+
- name: Define mysql_config_file.
42+
set_fact:
43+
mysql_config_file: "{{ __mysql_config_file }}"
44+
when: mysql_config_file is not defined
45+
46+
- name: Define mysql_config_include_dir.
47+
set_fact:
48+
mysql_config_include_dir: "{{ __mysql_config_include_dir }}"
49+
when: mysql_config_include_dir is not defined
50+
51+
- name: Define mysql_socket.
52+
set_fact:
53+
mysql_socket: "{{ __mysql_socket }}"
54+
when: mysql_socket is not defined
55+
56+
- name: Define mysql_supports_innodb_large_prefix.
57+
set_fact:
58+
mysql_supports_innodb_large_prefix: "{{ __mysql_supports_innodb_large_prefix }}"
59+
when: mysql_supports_innodb_large_prefix is not defined

vars/Debian.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ __mysql_packages:
44
- mysql-common
55
- mysql-server
66
__mysql_slow_query_log_file: /var/log/mysql/mysql-slow.log
7-
mysql_config_file: /etc/mysql/my.cnf
8-
mysql_config_include_dir: /etc/mysql/conf.d
9-
mysql_socket: /var/run/mysqld/mysqld.sock
7+
__mysql_log_error: /var/log/mysql.err
8+
__mysql_syslog_tag: mysql
9+
__mysql_pid_file: /var/run/mysqld/mysqld.pid
10+
__mysql_config_file: /etc/mysql/my.cnf
11+
__mysql_config_include_dir: /etc/mysql/conf.d
12+
__mysql_socket: /var/run/mysqld/mysqld.sock
1013
__mysql_supports_innodb_large_prefix: true

vars/RedHat-6.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ __mysql_packages:
44
- mysql
55
- mysql-server
66
__mysql_slow_query_log_file: /var/log/mysql-slow.log
7-
mysql_config_file: /etc/my.cnf
8-
mysql_config_include_dir: /etc/my.cnf.d
9-
mysql_socket: /var/lib/mysql/mysql.sock
7+
__mysql_log_error: /var/log/mysql.err
8+
__mysql_syslog_tag: mysql
9+
__mysql_pid_file: /var/run/mysqld/mysqld.pid
10+
__mysql_config_file: /etc/my.cnf
11+
__mysql_config_include_dir: /etc/my.cnf.d
12+
__mysql_socket: /var/lib/mysql/mysql.sock
1013
__mysql_supports_innodb_large_prefix: false

vars/RedHat-7.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ __mysql_packages:
77
- MySQL-python
88
- perl-DBD-MySQL
99
__mysql_slow_query_log_file: /var/log/mysql-slow.log
10-
mysql_log_error: /var/log/mariadb/mariadb.log
11-
mysql_syslog_tag: mariadb
12-
mysql_pid_file: /var/run/mariadb/mariadb.pid
13-
mysql_config_file: /etc/my.cnf
14-
mysql_config_include_dir: /etc/my.cnf.d
15-
mysql_socket: /var/lib/mysql/mysql.sock
10+
__mysql_log_error: /var/log/mariadb/mariadb.log
11+
__mysql_syslog_tag: mariadb
12+
__mysql_pid_file: /var/run/mariadb/mariadb.pid
13+
__mysql_config_file: /etc/my.cnf
14+
__mysql_config_include_dir: /etc/my.cnf.d
15+
__mysql_socket: /var/lib/mysql/mysql.sock
1616
__mysql_supports_innodb_large_prefix: true

0 commit comments

Comments
 (0)