You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+84-48Lines changed: 84 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -8,59 +8,79 @@ Installs and configures MySQL or MariaDB server on RHEL/CentOS or Debian/Ubuntu
8
8
9
9
No special requirements; note that this role requires root access, so either run it in a playbook with a global `become: yes`, or invoke the role in your playbook like:
10
10
11
-
- hosts: database
12
-
roles:
13
-
- role: geerlingguy.mysql
14
-
become: yes
11
+
```yaml
12
+
- hosts: database
13
+
roles:
14
+
- role: geerlingguy.mysql
15
+
become: yes
16
+
```
15
17
16
18
## Role Variables
17
19
18
20
Available variables are listed below, along with default values (see `defaults/main.yml`):
19
21
20
-
mysql_user_home: /root
21
-
mysql_user_name: root
22
-
mysql_user_password: root
22
+
```yaml
23
+
mysql_user_home: /root
24
+
mysql_user_name: root
25
+
mysql_user_password: root
26
+
```
23
27
24
28
The home directory inside which Python MySQL settings will be stored, which Ansible will use when connecting to MySQL. This should be the home directory of the user which runs this Ansible role. The `mysql_user_name` and `mysql_user_password` can be set if you are running this role under a non-root user account and want to set a non-root user.
25
29
26
-
mysql_root_home: /root
27
-
mysql_root_username: root
28
-
mysql_root_password: root
30
+
```yaml
31
+
mysql_root_home: /root
32
+
mysql_root_username: root
33
+
mysql_root_password: root
34
+
```
29
35
30
36
The MySQL root user account details.
31
37
32
-
mysql_root_password_update: false
38
+
```yaml
39
+
mysql_root_password_update: false
40
+
```
33
41
34
42
Whether to force update the MySQL root user's password. By default, this role will only change the root user's password when MySQL is first configured. You can force an update by setting this to `yes`.
35
43
36
44
> Note: If you get an error like `ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)` after a failed or interrupted playbook run, this usually means the root password wasn't originally updated to begin with. Try either removing the `.my.cnf` file inside the configured `mysql_user_home` or updating it and setting `password=''` (the insecure default password). Run the playbook again, with `mysql_root_password_update` set to `yes`, and the setup should complete.
37
45
38
46
> Note: If you get an error like `ERROR 1698 (28000): Access denied for user 'root'@'localhost' (using password: YES)` when trying to log in from the CLI you might need to run as root or sudoer.
39
47
40
-
mysql_enabled_on_startup: true
48
+
```yaml
49
+
mysql_enabled_on_startup: true
50
+
```
41
51
42
52
Whether MySQL should be enabled on startup.
43
53
44
-
mysql_config_file: *default value depends on OS*
45
-
mysql_config_include_dir: *default value depends on OS*
46
-
54
+
```yaml
55
+
mysql_config_file: *default value depends on OS*
56
+
mysql_config_include_dir: *default value depends on OS*
57
+
```
58
+
47
59
The main my.cnf configuration file and include directory.
48
60
49
-
overwrite_global_mycnf: true
61
+
```yaml
62
+
overwrite_global_mycnf: true
63
+
```
50
64
51
65
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.
52
66
53
-
mysql_config_include_files: []
67
+
```yaml
68
+
mysql_config_include_files: []
69
+
```
54
70
55
71
A list of files that should override the default global my.cnf. Each item in the array requires a "src" parameter which is a path to a file. An optional "force" parameter can force the file to be updated each time ansible runs.
56
72
57
-
mysql_databases: []
73
+
```yaml
74
+
mysql_databases: []
75
+
```
58
76
59
77
The MySQL databases to create. A database has the values `name`, `encoding` (defaults to `utf8`), `collation` (defaults to `utf8_general_ci`) and `replicate` (defaults to `1`, only used if replication is configured). The formats of these are the same as in the `mysql_db` module.
60
78
61
79
You can also delete a database (or ensure it's not on the server) by setting `state` to `absent` (defaults to `present`).
62
80
63
-
mysql_users: []
81
+
```yaml
82
+
mysql_users: []
83
+
```
64
84
65
85
The MySQL users and their privileges. A user has the values:
66
86
@@ -74,55 +94,71 @@ The MySQL users and their privileges. A user has the values:
74
94
75
95
The formats of these are the same as in the `mysql_user` module.
76
96
77
-
mysql_packages:
78
-
- mysql
79
-
- mysql-server
97
+
```yaml
98
+
mysql_packages:
99
+
- mysql
100
+
- mysql-server
101
+
```
80
102
81
103
(OS-specific, RedHat/CentOS defaults listed here) Packages to be installed. In some situations, you may need to add additional packages, like `mysql-devel`.
82
104
83
-
mysql_enablerepo: ""
105
+
```yaml
106
+
mysql_enablerepo: ""
107
+
```
84
108
85
109
(RedHat/CentOS only) If you have enabled any additional repositories (might I suggest geerlingguy.repo-epel or geerlingguy.repo-remi), those repositories can be listed under this variable (e.g. `remi,epel`). This can be handy, as an example, if you want to install later versions of MySQL.
86
110
87
-
mysql_python_package_debian: python3-mysqldb
111
+
```yaml
112
+
mysql_python_package_debian: python3-mysqldb
113
+
```
88
114
89
115
(Ubuntu/Debian only) If you need to explicitly override the MySQL Python package, you can set it here. Set this to `python-mysqldb` if using older distributions running Python 2.
90
116
91
-
mysql_port: "3306"
92
-
mysql_bind_address: '0.0.0.0'
93
-
mysql_datadir: /var/lib/mysql
94
-
mysql_socket: *default value depends on OS*
95
-
mysql_pid_file: *default value depends on OS*
117
+
```yaml
118
+
mysql_port: "3306"
119
+
mysql_bind_address: '0.0.0.0'
120
+
mysql_datadir: /var/lib/mysql
121
+
mysql_socket: *default value depends on OS*
122
+
mysql_pid_file: *default value depends on OS*
123
+
```
96
124
97
125
Default MySQL connection configuration.
98
126
99
-
mysql_log_file_group: mysql *adm on Debian*
100
-
mysql_log: ""
101
-
mysql_log_error: *default value depends on OS*
102
-
mysql_syslog_tag: *default value depends on OS*
127
+
```yaml
128
+
mysql_log_file_group: mysql *adm on Debian*
129
+
mysql_log: ""
130
+
mysql_log_error: *default value depends on OS*
131
+
mysql_syslog_tag: *default value depends on OS*
132
+
```yaml
103
133
104
134
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`.
105
135
106
-
mysql_slow_query_log_enabled: false
107
-
mysql_slow_query_log_file: *default value depends on OS*
108
-
mysql_slow_query_time: 2
136
+
```yaml
137
+
mysql_slow_query_log_enabled: false
138
+
mysql_slow_query_log_file: *default value depends on OS*
139
+
mysql_slow_query_time: 2
140
+
```
109
141
110
142
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`.
111
143
112
-
mysql_key_buffer_size: "256M"
113
-
mysql_max_allowed_packet: "64M"
114
-
mysql_table_open_cache: "256"
115
-
[...]
144
+
```yaml
145
+
mysql_key_buffer_size: "256M"
146
+
mysql_max_allowed_packet: "64M"
147
+
mysql_table_open_cache: "256"
148
+
...
149
+
```
116
150
117
-
The rest of the settings in `defaults/main.yml` control MySQL's memory usage and some other common settings. The default values are tuned for a server where MySQL can consume ~512 MB RAM, so you should consider adjusting them to suit your particular server better.
151
+
The rest of the settings in `defaults/main.yml` control MySQL's memory usage and some other common settings. The default values are tuned for a server where MySQL can consume 512 MB RAM, so you should consider adjusting them to suit your particular server better.
118
152
119
-
mysql_server_id: "1"
120
-
mysql_max_binlog_size: "100M"
121
-
mysql_binlog_format: "ROW"
122
-
mysql_expire_logs_days: "10"
123
-
mysql_replication_role: ''
124
-
mysql_replication_master: ''
125
-
mysql_replication_user: {}
153
+
```yaml
154
+
mysql_server_id: "1"
155
+
mysql_max_binlog_size: "100M"
156
+
mysql_binlog_format: "ROW"
157
+
mysql_expire_logs_days: "10"
158
+
mysql_replication_role: ''
159
+
mysql_replication_master: ''
160
+
mysql_replication_user: {}
161
+
```
126
162
127
163
Replication settings. Set `mysql_server_id` and `mysql_replication_role` by server (e.g. the master would be ID `1`, with the `mysql_replication_role` of `master`, and the slave would be ID `2`, with the `mysql_replication_role` of `slave`). The `mysql_replication_user` uses the same keys as individual list items in `mysql_users`, and is created on master servers, and used to replicate on all the slaves.
0 commit comments