Issue #6: Add replication configuration.

pull/63/head
Jeff Geerling 10 years ago
parent 181aef9806
commit 6967874c08
  1. 22
      defaults/main.yml
  2. 8
      tasks/databases.yml
  3. 4
      tasks/main.yml
  4. 51
      tasks/replication.yml
  5. 8
      tasks/users.yml
  6. 29
      templates/my.cnf.j2

@ -40,13 +40,29 @@ mysql_innodb_log_buffer_size: "8M"
mysql_innodb_flush_log_at_trx_commit: "1"
mysql_innodb_lock_wait_timeout: 50
# mysqldump settings
# mysqldump settings.
mysql_mysqldump_max_allowed_packet: "64M"
# mysqld_safe setting
# Logging settings.
mysql_log_error: /var/log/mysqld.log
mysql_syslog_tag: mysqld
# databases and users settings
# Databases.
mysql_databases: []
# Full example:
# mysql_databases:
# - { name: example, collation: utf8_general_ci, encoding: utf8, replicate: 1 }
# Users
mysql_users: []
# Full Example:
# mysql_users:
# - { name: example, host: 127.0.0.1, password: secret, priv: *.*:USAGE }
# Replication settings (replication is only enabled if master/user have values).
mysql_server_id: "1"
mysql_max_binlog_size: "100M"
mysql_replication_role: master
mysql_replication_master: ''
# Same keys as `mysql_users` above.
mysql_replication_user: []

@ -0,0 +1,8 @@
---
- 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

@ -10,4 +10,6 @@
- include: configure.yml
- include: secure-installation.yml
- include: databases-users.yml
- include: databases.yml
- include: users.yml
- include: replication.yml

@ -0,0 +1,51 @@
---
- name: Ensure replication user exists on master.
mysql_user:
name: "{{ mysql_replication_user.name }}"
host: "{{ mysql_replication_user.host | default('%') }}"
password: "{{ mysql_replication_user.password }}"
priv: "{{ mysql_replication_user.priv | default('*.*:REPLICATION SLAVE') }}"
state: present
when: >
(mysql_replication_role == 'master')
and mysql_replication_user
and (mysql_replication_master != '')
- name: Check slave replication status.
mysql_replication: mode=getslave
ignore_errors: true
register: slave
when: >
mysql_replication_role == 'slave'
and (mysql_replication_master != '')
- name: Check master replication status.
mysql_replication: mode=getmaster
delegate_to: "{{ mysql_replication_master }}"
register: master
when: >
slave|failed
and (mysql_replication_role == 'slave')
and (mysql_replication_master != '')
- name: Configure replication on the slave.
mysql_replication:
mode: changemaster
master_host: "{{ mysql_replication_master }}"
master_user: "{{ mysql_replication_user.name }}"
master_password: "{{ mysql_replication_user.password }}"
master_log_file: "{{ master.File }}"
master_log_pos: "{{ master.Position }}"
ignore_errors: True
when: >
slave|failed
and (mysql_replication_role == 'slave')
and (mysql_replication_master != '')
and mysql_replication_user
- name: Start replication.
mysql_replication: mode=startslave
when: >
slave|failed
and (mysql_replication_role == 'slave')
and (mysql_replication_master != '')

@ -1,12 +1,4 @@
---
- 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 }}"

@ -8,13 +8,34 @@ port = {{ mysql_port }}
datadir = {{ mysql_datadir }}
socket = {{ mysql_socket }}
# Replication
server-id = {{ mysql_server_id }}
{% if mysql_replication_role == 'master' %}
log_bin = mysql-bin
log-bin-index = mysql-bin.index
expire_logs_days = 10
max_binlog_size = {{ mysql_max_binlog_size }}
{% for db in mysql_databases %}
{% if db.replicate|default(1) %}
binlog_do_db = {{ db.name }}
{% else %}
binlog_ignore_db = {{ db.name }}
{% endif %}
{% endfor %}
{% endif %}
{% if mysql_replication_role == 'slave' %}
read_only
relay-log = relay-bin
relay-log-index = relay-bin.index
{% endif %}
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links = 0
# Settings user and group are ignored when systemd is used (fedora >= 15).
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
# User is ignored when systemd is used (fedora <= 15).
user = mysql
# http://dev.mysql.com/doc/refman/5.5/en/performance-schema.html