Skip to content

Commit e070c0d

Browse files
author
Colin Hoglund
committed
merge upstream master
2 parents 9895a7b + 5e70f6e commit e070c0d

17 files changed

+175
-154
lines changed

.travis.yml

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,55 @@
11
---
2-
sudo: required
2+
services: docker
33

44
env:
5-
- distribution: centos
6-
version: 6
5+
- distro: centos7
6+
init: /usr/lib/systemd/systemd
7+
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
8+
playbook: centos-7-test.yml
9+
- distro: centos6
710
init: /sbin/init
811
run_opts: ""
912
playbook: test.yml
10-
- distribution: centos
11-
version: 7
12-
init: /usr/lib/systemd/systemd
13+
- distro: ubuntu1604
14+
init: /lib/systemd/systemd
1315
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
14-
playbook: centos-7-test.yml
15-
- distribution: ubuntu
16-
version: 14.04
16+
playbook: test.yml
17+
- distro: ubuntu1404
1718
init: /sbin/init
1819
run_opts: ""
1920
playbook: test.yml
20-
# - distribution: ubuntu
21-
# version: 12.04
22-
# init: /sbin/init
23-
# run_opts: ""
24-
# playbook: test.yml
2521

2622
services:
2723
- docker
2824

2925
before_install:
3026
# Pull container
31-
- 'sudo docker pull ${distribution}:${version}'
32-
# Customize container
33-
- 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
27+
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'
3428

3529
script:
3630
- container_id=$(mktemp)
37-
# Run container in detached state
38-
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'
31+
# Run container in detached state.
32+
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
3933

4034
# Ansible syntax check.
41-
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} --syntax-check'
35+
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} --syntax-check'
4236

4337
# Test role.
44-
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}'
38+
- 'docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}'
4539

4640
# Test role idempotence.
41+
- idempotence=$(mktemp)
42+
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} | tee -a ${idempotence}
4743
- >
48-
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}
44+
tail ${idempotence}
4945
| grep -q 'changed=0.*failed=0'
5046
&& (echo 'Idempotence test: pass' && exit 0)
5147
|| (echo 'Idempotence test: fail' && exit 1)
5248
5349
# Some MySQL debugging (show all the logs).
54-
- sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ls -lah /var/log
55-
- sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql/error.log || true
56-
- sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.err || true
50+
- docker exec --tty "$(cat ${container_id})" env TERM=xterm ls -lah /var/log
51+
- docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql/error.log || true
52+
- docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.err || true
5753

5854
# Check to make sure we can connect to MySQL via Unix socket.
5955
- >
@@ -69,8 +65,11 @@ script:
6965
&& (echo 'MySQL running normally' && exit 0)
7066
|| (echo 'MySQL not running' && exit 1)
7167
72-
# Clean up
73-
- sudo docker stop "$(cat ${container_id})"
68+
after_failure:
69+
# Check MySQL settings.
70+
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql/error.log'
71+
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.err'
72+
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.log'
7473

7574
notifications:
7675
webhooks: https://galaxy.ansible.com/api/v1/notifications/

README.md

Lines changed: 13 additions & 5 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`.
@@ -84,10 +91,11 @@ Slow query log settings. Note that the log file will be created by this role, bu
8491
mysql_table_open_cache: "256"
8592
[...]
8693

87-
The rest of the settings in `defaults/main.yml` control MySQL's memory usage. 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.
94+
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.
8895

8996
mysql_server_id: "1"
9097
mysql_max_binlog_size: "100M"
98+
mysql_binlog_format: "ROW"
9199
mysql_expire_logs_days: "10"
92100
mysql_replication_role: ''
93101
mysql_replication_master: ''
@@ -140,4 +148,4 @@ MIT / BSD
140148

141149
## Author Information
142150

143-
This role was created in 2014 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/).
151+
This role was created in 2014 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).

defaults/main.yml

Lines changed: 27 additions & 10 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
35-
mysql_slow_query_time: 2
40+
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"
@@ -44,28 +51,37 @@ mysql_read_rnd_buffer_size: "4M"
4451
mysql_myisam_sort_buffer_size: "64M"
4552
mysql_thread_cache_size: "8"
4653
mysql_query_cache_size: "16M"
47-
mysql_max_connections: 151
54+
mysql_query_cache_limit: "1M"
55+
mysql_max_connections: "151"
56+
mysql_tmp_table_size: "16M"
57+
mysql_max_heap_table_size: "16M"
4858

4959
# Other settings.
50-
mysql_wait_timeout: 28800
60+
mysql_lower_case_table_names: "0"
61+
mysql_wait_timeout: "28800"
5162

5263
# InnoDB settings.
53-
# Set .._buffer_pool_size up to 80% of RAM but beware of setting too high.
5464
mysql_innodb_file_per_table: "1"
65+
# Set .._buffer_pool_size up to 80% of RAM but beware of setting too high.
5566
mysql_innodb_buffer_pool_size: "256M"
5667
# Set .._log_file_size to 25% of buffer pool size.
5768
mysql_innodb_log_file_size: "64M"
5869
mysql_innodb_log_buffer_size: "8M"
5970
mysql_innodb_flush_log_at_trx_commit: "1"
60-
mysql_innodb_lock_wait_timeout: 50
71+
mysql_innodb_lock_wait_timeout: "50"
72+
73+
# These settings require MySQL > 5.5.
74+
mysql_innodb_large_prefix: "1"
75+
mysql_innodb_file_format: "barracuda"
6176

6277
# mysqldump settings.
6378
mysql_mysqldump_max_allowed_packet: "64M"
6479

6580
# Logging settings.
6681
mysql_log: ""
67-
mysql_log_error: /var/log/mysql.err
68-
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
6985

7086
mysql_config_include_files: []
7187
# - src: path/relative/to/playbook/file.cnf
@@ -88,6 +104,7 @@ mysql_users: []
88104
# Replication settings (replication is only enabled if master/user have values).
89105
mysql_server_id: "1"
90106
mysql_max_binlog_size: "100M"
107+
mysql_binlog_format: "ROW"
91108
mysql_expire_logs_days: "10"
92109
mysql_replication_role: ''
93110
mysql_replication_master: ''

tasks/main.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
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
3+
- include: variables.yml
254

265
# Setup/install tasks.
276
- include: setup-RedHat.yml
287
when: ansible_os_family == 'RedHat'
8+
static: no
299

3010
- include: setup-Debian.yml
3111
when: ansible_os_family == 'Debian'
12+
static: no
3213

3314
- name: Check if MySQL packages were installed.
3415
set_fact:

tasks/replication.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
delegate_to: "{{ mysql_replication_master }}"
2525
register: master
2626
when: >
27-
slave|failed
27+
((slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave|failed))
2828
and (mysql_replication_role == 'slave')
2929
and (mysql_replication_master != '')
3030
@@ -38,14 +38,14 @@
3838
master_log_pos: "{{ master.Position }}"
3939
ignore_errors: True
4040
when: >
41-
slave|failed
41+
((slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave|failed))
4242
and (mysql_replication_role == 'slave')
4343
and (mysql_replication_master != '')
4444
and mysql_replication_user
4545
4646
- name: Start replication.
4747
mysql_replication: mode=startslave
4848
when: >
49-
slave|failed
49+
((slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave|failed))
5050
and (mysql_replication_role == 'slave')
5151
and (mysql_replication_master != '')

tasks/secure-installation.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
shell: >
2424
mysql -u root -NBe
2525
'ALTER USER "{{ mysql_root_username }}"@"{{ item }}" IDENTIFIED WITH mysql_native_password BY "{{ mysql_root_password }}";'
26-
with_items: "{{ mysql_root_hosts.stdout_lines | default([]) }}"
26+
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
2727
when: ((mysql_install_packages | bool) or mysql_root_password_update) and ('5.7.' in mysql_cli_version.stdout)
2828

2929
# Set root password for MySQL < 5.7.x.
3030
- name: Update MySQL root password for localhost root account (< 5.7.x).
3131
shell: >
3232
mysql -u root -NBe
3333
'SET PASSWORD FOR "{{ mysql_root_username }}"@"{{ item }}" = PASSWORD("{{ mysql_root_password }}");'
34-
with_items: "{{ mysql_root_hosts.stdout_lines | default([]) }}"
34+
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
3535
when: ((mysql_install_packages | bool) or mysql_root_password_update) and ('5.7.' not in mysql_cli_version.stdout)
3636

3737
# Has to be after the root password assignment, for idempotency.
@@ -54,7 +54,7 @@
5454
name: ""
5555
host: "{{ item }}"
5656
state: absent
57-
with_items: "{{ mysql_anonymous_hosts.stdout_lines | default([]) }}"
57+
with_items: "{{ mysql_anonymous_hosts.stdout_lines|default([]) }}"
5858

5959
- name: Remove MySQL test database.
6060
mysql_db: "name='test' state=absent"

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

0 commit comments

Comments
 (0)