Better code display

pull/29/head
Emilien Mantel 2018-03-17 18:28:56 +01:00
parent c72c3ac842
commit cc3bef8bfa
16 changed files with 161 additions and 94 deletions

View File

@ -1,7 +1,9 @@
--- ---
- name: TEMPLATE | Deploy Galera configuration - name: TEMPLATE | Deploy Galera configuration
template: src=etc/mysql/conf.d/09-galera.cnf.j2 dest=/etc/mysql/conf.d/09-galera.cnf template:
src: etc/mysql/conf.d/09-galera.cnf.j2
dest: /etc/mysql/conf.d/09-galera.cnf
register: galeraconfig register: galeraconfig
- name: INCLUDE | Bootstrap first node - name: INCLUDE | Bootstrap first node
@ -13,7 +15,9 @@
when: inventory_hostname != mariadb_galera_primary_node when: inventory_hostname != mariadb_galera_primary_node
- name: SERVICE | Restart MariaDB if needed - name: SERVICE | Restart MariaDB if needed
service: name=mysql state=restarted service:
name: mysql
state: restarted
when: > when: >
((galeraconfig or (p is defined and p.changed)) and ((galeraconfig or (p is defined and p.changed)) and
(bootstrap_run is not defined)) or (bootstrap_run is not defined)) or

View File

@ -14,18 +14,22 @@
- block: - block:
- name: SERVICE | Stop MariaDB - name: SERVICE | Stop MariaDB
service: name=mysql state=stopped service:
name: mysql
state: stopped
- name: COPY | Paste primary node's debian.cnf - name: COPY | Paste primary node's debian.cnf
copy: > copy:
content={{ debiancnf.stdout }} content: "{{ debiancnf.stdout }}"
dest=/etc/mysql/debian.cnf dest: /etc/mysql/debian.cnf
mode=0600 mode: 0600
owner=root owner: root
group=root group: root
register: paste register: paste
- name: SERVICE | Start MariaDB - name: SERVICE | Start MariaDB
service: name=mysql state=started service:
name: mysql
state: started
when: debiancnf.stdout != ondc.stdout when: debiancnf.stdout != ondc.stdout

View File

@ -1,21 +1,31 @@
--- ---
- name: SHELL | Get MariaDB target version - name: SHELL | Get MariaDB target version
shell: LANG=C apt-cache depends mariadb-server | awk -F '-' '/Depends/ { print $NF }' shell: "LANG=C apt-cache depends mariadb-server | awk -F '-' '/Depends/ { print $NF }'"
register: apt_mariadb_version register: apt_mariadb_version
changed_when: false changed_when: false
- name: DEBCONF | Prepare MariaDB silent installation (root password) - name: DEBCONF | Prepare MariaDB silent installation (root password)
debconf: name='mariadb-server-{{ apt_mariadb_version.stdout }}' question='mysql-server/root_password' vtype='password' value='{{ mariadb_root_password }}' debconf:
name: 'mariadb-server-{{ apt_mariadb_version.stdout }}'
question: 'mysql-server/root_password'
vtype: 'password'
value: '{{ mariadb_root_password }}'
when: not mariadb_exists.stat.exists when: not mariadb_exists.stat.exists
- name: DEBCONF | Prepare MariaDB silent installation (root password again) - name: DEBCONF | Prepare MariaDB silent installation (root password again)
debconf: name='mariadb-server-{{ apt_mariadb_version.stdout }}' question='mysql-server/root_password_again' vtype='password' value='{{ mariadb_root_password }}' debconf:
name: 'mariadb-server-{{ apt_mariadb_version.stdout }}'
question: 'mysql-server/root_password_again'
vtype: 'password'
value: '{{ mariadb_root_password }}'
when: not mariadb_exists.stat.exists when: not mariadb_exists.stat.exists
- name: APT | Install MariaDB server - name: APT | Install MariaDB server
apt: pkg=mariadb-server state=present apt:
pkg: mariadb-server
- name: APT | Install Galera - name: APT | Install Galera
apt: pkg=galera-3 state=present apt:
pkg: galera-3
when: mariadb_vendor == 'mariadb_galera' when: mariadb_vendor == 'mariadb_galera'

View File

@ -1,17 +1,23 @@
--- ---
- name: APT_KEY | Install MariaDB key - name: APT_KEY | Install MariaDB key
apt_key: keyserver="{{ mariadb_mariadb_key_server }}" id={{ item }} state=present apt_key:
with_items: "{{ mariadb_mariadb_key_ids }}" keyserver: "{{ mariadb_key_server }}"
id: "{{ item }}"
with_items: "{{ mariadb_key_ids }}"
- name: TEMPLATE | Deploy APT pinning (prevent upgrades from Debian) - name: TEMPLATE | Deploy APT pinning (prevent upgrades from Debian)
template: src=etc/apt/preferences.d/95-mariadb.j2 dest=/etc/apt/preferences.d/95-mariadb template:
src: etc/apt/preferences.d/95-mariadb.j2
dest: /etc/apt/preferences.d/95-mariadb
- name: APT_REPOSITORY | Add MariaDB repository - name: APT_REPOSITORY | Add MariaDB repository
apt_repository: repo='deb {{ mariadb_mariadb_repository }} {{ ansible_distribution_release }} main' state=present apt_repository:
repo: 'deb {{ mariadb_repository }} {{ ansible_distribution_release }} main'
- name: APT_REPOSITORY | Add MariaDB (src) repository - name: APT_REPOSITORY | Add MariaDB (src) repository
apt_repository: repo='deb-src {{ mariadb_mariadb_repository }} {{ ansible_distribution_release }} main' state=present apt_repository:
repo: 'deb-src {{ mariadb_repository }} {{ ansible_distribution_release }} main'
when: mariadb_upstream_apt_src when: mariadb_upstream_apt_src
- name: INCLUDE | Normal Install - name: INCLUDE | Normal Install

View File

@ -1,15 +1,20 @@
--- ---
- name: APT_KEY | Install Percona key - name: APT_KEY | Install Percona key
apt_key: keyserver="keyserver.ubuntu.com" id="8507EFA5" state=present apt_key:
keyserver: "keyserver.ubuntu.com"
id: "8507EFA5"
- name: TEMPLATE | Deploy APT pinning (prevent upgrades from Debian) - name: TEMPLATE | Deploy APT pinning (prevent upgrades from Debian)
template: src=etc/apt/preferences.d/95-percona.j2 dest=/etc/apt/preferences.d/95-percona template:
src: etc/apt/preferences.d/95-percona.j2
dest: /etc/apt/preferences.d/95-percona
- name: APT_REPOSITORY | Add Percona repository - name: APT_REPOSITORY | Add Percona repository
apt_repository: repo='deb {{ mariadb_percona_repository }} {{ ansible_distribution_release }} main' state=present apt_repository:
repo: 'deb {{ mariadb_percona_repository }} {{ ansible_distribution_release }} main'
- name: APT_RESPOSITORY | Add Percona (src) repository - name: APT_RESPOSITORY | Add Percona (src) repository
apt_repository: repo='deb-src {{ mariadb_percona_repository }} {{ ansible_distribution_release }} main' state=present apt_repository:
repo: 'deb-src {{ mariadb_percona_repository }} {{ ansible_distribution_release }} main'
when: mariadb_upstream_apt_src when: mariadb_upstream_apt_src

View File

@ -13,21 +13,33 @@
include: install/main.yml include: install/main.yml
- name: TEMPLATE | Deploy configuration - name: TEMPLATE | Deploy configuration
template: "src={{ mariadb_config_template }} dest=/etc/mysql/my.cnf" template:
src: "{{ mariadb_config_template }}"
dest: /etc/mysql/my.cnf
register: config register: config
- name: TEMPLATE | Deploy extra configuration - name: TEMPLATE | Deploy extra configuration
template: src=etc/mysql/conf.d/10-extra.cnf.j2 dest=/etc/mysql/conf.d/10-extra.cnf template:
src: etc/mysql/conf.d/10-extra.cnf.j2
dest: /etc/mysql/conf.d/10-extra.cnf
register: extraconfig register: extraconfig
- name: SERVICE | Restart now (prevent bugs) - name: SERVICE | Restart now (prevent bugs)
service: name=mysql state=restarted service:
name: mysql
state: restarted
when: > when: >
(config.changed or extraconfig.changed) and (config.changed or extraconfig.changed) and
not mariadb_galera_resetup not mariadb_galera_resetup
- name: TEMPLATE Create .my.cnf for root - name: TEMPLATE Create .my.cnf for root
template: src=root/my.cnf dest=/root/.my.cnf owner=root group=root mode=0600 backup=yes template:
src: root/my.cnf
dest: /root/.my.cnf
owner: root
group: root
mode: 0600
backup: yes
- name: INCLUDE | Galera - name: INCLUDE | Galera
include: galera/main.yml include: galera/main.yml
@ -41,19 +53,23 @@
include: 'secure.yml' include: 'secure.yml'
- name: SERVICE | Ensure service is started - name: SERVICE | Ensure service is started
service: name=mysql state=started service:
name: mysql
state: started
- name: MYSQL_DB | Create databases - name: MYSQL_DB | Create databases
mysql_db: name={{ item }} state=present mysql_db:
name: "{{ item }}"
state: present
with_items: "{{ mariadb_databases }}" with_items: "{{ mariadb_databases }}"
- name: MYSQL_USER | Manages users... - name: MYSQL_USER | Manages users...
mysql_user: > mysql_user:
name="{{ item.name }}" name: "{{ item.name }}"
password="{{ item.password }}" password: "{{ item.password }}"
priv="{{ item.priv }}" priv: "{{ item.priv }}"
host="{{ item.host | default('localhost') }}" host: "{{ item.host | default('localhost') }}"
state=present state: present
with_items: "{{ mariadb_users }}" with_items: "{{ mariadb_users }}"
- name: TEMPLATE | Deploy logrotate configuration - name: TEMPLATE | Deploy logrotate configuration

View File

@ -7,4 +7,3 @@
- name: INCLUDE | Replication slave - name: INCLUDE | Replication slave
include: slave.yml include: slave.yml
when: mariadb_replication_slave when: mariadb_replication_slave

View File

@ -1,7 +1,7 @@
--- ---
- name: TEMPLATE | Deploy master configuration - name: TEMPLATE | Deploy master configuration
template: > template:
src=etc/mysql/conf.d/50-master.cnf.j2 src: etc/mysql/conf.d/50-master.cnf.j2
dest=/etc/mysql/conf.d/50-master.cnf dest: /etc/mysql/conf.d/50-master.cnf
notify: restart mariadb notify: restart mariadb

View File

@ -1,17 +1,20 @@
--- ---
- name: MYSQL_VARIABLES | Set read only - name: MYSQL_VARIABLES | Set read only
mysql_variables: variable=read_only value=ON mysql_variables:
variable: read_only
value: 'ON'
when: mariadb_slave_readonly when: mariadb_slave_readonly
- name: TEMPLATE | Deploy slave configuration - name: TEMPLATE | Deploy slave configuration
template: > template:
src=etc/mysql/conf.d/51-slave.cnf.j2 src: etc/mysql/conf.d/51-slave.cnf.j2
dest=/etc/mysql/conf.d/51-slave.cnf dest: /etc/mysql/conf.d/51-slave.cnf
notify: restart mariadb notify: restart mariadb
- name: MYSQL_REPLICATION | Get slave status - name: MYSQL_REPLICATION | Get slave status
mysql_replication: mode=getslave mysql_replication:
mode: getslave
ignore_errors: yes ignore_errors: yes
register: slave_status register: slave_status
@ -32,7 +35,8 @@
when: mariadb_slave_replicate_mysqldb when: mariadb_slave_replicate_mysqldb
- name: MYSQL_REPLICATION | Get slave status - name: MYSQL_REPLICATION | Get slave status
mysql_replication: mode=getslave mysql_replication:
mode: getslave
ignore_errors: yes ignore_errors: yes
register: slave_status register: slave_status

View File

@ -1,10 +1,10 @@
--- ---
- name: FETCH | Get /etc/mysql/debian.cnf on master - name: FETCH | Get /etc/mysql/debian.cnf on master
fetch: > fetch:
src=/etc/mysql/debian.cnf src: /etc/mysql/debian.cnf
dest=/tmp/{{ mariadb_slave_import_from }}/debian.cnf dest: /tmp/{{ mariadb_slave_import_from }}/debian.cnf
flat=yes flat: yes
changed_when: false changed_when: false
delegate_to: "{{ mariadb_slave_import_from }}" delegate_to: "{{ mariadb_slave_import_from }}"
@ -13,9 +13,10 @@
become: no become: no
- name: COPY | Fetched file to /etc/mysql/debian.cnf - name: COPY | Fetched file to /etc/mysql/debian.cnf
copy: > copy:
src=/tmp/{{ mariadb_slave_import_from }}/debian.cnf src: "/tmp/{{ mariadb_slave_import_from }}/debian.cnf"
dest=/etc/mysql/debian.cnf dest: /etc/mysql/debian.cnf
owner=root group=root mode=0600 owner: root
group: root
mode: 0600
notify: restart mariadb notify: restart mariadb

View File

@ -2,7 +2,9 @@
# Doc: https://www.percona.com/doc/percona-xtrabackup/2.1/howtos/recipes_ibkx_gtid.html # Doc: https://www.percona.com/doc/percona-xtrabackup/2.1/howtos/recipes_ibkx_gtid.html
- name: WAIT_FOR | source data (prevent rsync bug) - TODO find another hack - name: WAIT_FOR | source data (prevent rsync bug) - TODO find another hack
wait_for: host={{ mariadb_slave_import_from }} port=22 wait_for:
host: "{{ mariadb_slave_import_from }}"
port: 22
- name: COMMAND | Prepare backup another server - name: COMMAND | Prepare backup another server
command: innobackupex --no-timestamp {{ mariadb_backup_dir }} creates={{ mariadb_backup_dir }} command: innobackupex --no-timestamp {{ mariadb_backup_dir }} creates={{ mariadb_backup_dir }}
@ -10,12 +12,14 @@
register: backup register: backup
- name: SHELL | Dump - name: SHELL | Dump
shell: innobackupex --apply-log {{ mariadb_backup_dir }} shell: "innobackupex --apply-log {{ mariadb_backup_dir }}"
delegate_to: "{{ mariadb_slave_import_from }}" delegate_to: "{{ mariadb_slave_import_from }}"
when: backup.changed when: backup.changed
- name: FILE | Remove mysql db from backup - name: FILE | Remove mysql db from backup
file: path={{ mariadb_backup_dir }}/mysql state=absent file:
path: "{{ mariadb_backup_dir }}/mysql"
state: absent
delegate_to: "{{ mariadb_slave_import_from }}" delegate_to: "{{ mariadb_slave_import_from }}"
when: backup.changed and not mariadb_slave_replicate_mysqldb when: backup.changed and not mariadb_slave_replicate_mysqldb
@ -25,38 +29,42 @@
- name: SET_FACT | related to mysql datadir - name: SET_FACT | related to mysql datadir
set_fact: set_fact:
mariadb_mariadb_datadir: "{{ datadir.msg }}" mariadb_datadir: "{{ datadir.msg }}"
mariadb_binlog_info: "{{ datadir.msg }}/xtrabackup_binlog_info" mariadb_binlog_info: "{{ datadir.msg }}/xtrabackup_binlog_info"
- name: SERVICE | Stop MySQL before importing data - name: SERVICE | Stop MySQL before importing data
service: name=mysql state=stopped service:
name: mysql
state: stopped
# TODO: add an "ignore warning" # TODO: add an "ignore warning"
- name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mariadb_backup_user is not working) - name: COMMAND | Sync backup to slave - TODO remove vagrant as static user (see why mariadb_backup_user is not working)
shell: "sudo -E rsync --rsync-path='sudo rsync' -a -e 'ssh -o StrictHostKeyChecking=no' {{ mariadb_backup_user }}@{{ mariadb_slave_import_from }}:{{ mariadb_backup_dir }}/ {{ mariadb_mariadb_datadir }}/" shell: "sudo -E rsync --rsync-path='sudo rsync' -a -e 'ssh -o StrictHostKeyChecking=no' {{ mariadb_backup_user }}@{{ mariadb_slave_import_from }}:{{ mariadb_backup_dir }}/ {{ mariadb_datadir }}/"
become: no become: no
- name: FILE | Re-apply owner - name: FILE | Re-apply owner
file: > file:
path={{ mariadb_mariadb_datadir }} path: "{{ mariadb_datadir }}"
state=directory state: directory
owner=mysql owner: mysql
group=mysql group: mysql
recurse=yes recurse: yes
- name: SERVICE | Start MySQL - name: SERVICE | Start MariaDB
service: name=mysql state=started service:
name: mysql
state: started
- name: SHELL | Get master_log_file - name: SHELL | Get master_log_file
command: awk '{ print $1 }' {{ mariadb_binlog_info }} command: "awk '{ print $1 }' {{ mariadb_binlog_info }}"
register: master_log_file register: master_log_file
- name: SHELL | Get master_log_pos - name: SHELL | Get master_log_pos
command: awk '{ print $2 }' {{ mariadb_binlog_info }} command: "awk '{ print $2 }' {{ mariadb_binlog_info }}"
register: master_log_pos register: master_log_pos
- name: SHELL | Get master GTID - name: SHELL | Get master GTID
command: awk '{ print $3 }' {{ mariadb_binlog_info }} command: "awk '{ print $3 }' {{ mariadb_binlog_info }}"
register: master_gtid register: master_gtid
- name: SET_FACT | master_log_file - name: SET_FACT | master_log_file
@ -69,4 +77,3 @@
file: path={{ mariadb_backup_dir }} state=absent file: path={{ mariadb_backup_dir }} state=absent
delegate_to: "{{ mariadb_slave_import_from }}" delegate_to: "{{ mariadb_slave_import_from }}"
when: mariadb_slave_import_flush_dump when: mariadb_slave_import_flush_dump

View File

@ -5,10 +5,12 @@
# - https://mariadb.com/kb/en/mariadb/global-transaction-id/#switching-an-existing-old-style-slave-to-use-gtid # - https://mariadb.com/kb/en/mariadb/global-transaction-id/#switching-an-existing-old-style-slave-to-use-gtid
- name: MYSQL_REPLICATION | Stop slave - name: MYSQL_REPLICATION | Stop slave
mysql_replication: mode=stopslave mysql_replication:
mode: stopslave
- name: COMMAND | Migrate to MariaDB GTID - name: COMMAND | Migrate to MariaDB GTID
command: mysql -e "CHANGE MASTER TO master_use_gtid=current_pos"; command: mysql -e "CHANGE MASTER TO master_use_gtid=current_pos";
- name: MYSQL_REPLICATION | Start slave - name: MYSQL_REPLICATION | Start slave
mysql_replication: mode=startslave mysql_replication:
mode: startslave

View File

@ -1,22 +1,24 @@
--- ---
- name: MYSQL_REPLICATION | Stop slave - name: MYSQL_REPLICATION | Stop slave
mysql_replication: mode=stopslave mysql_replication:
mode: stopslave
- name: MYSQL_REPLICATION | Configure master host - name: MYSQL_REPLICATION | Configure master host
mysql_replication: > mysql_replication:
mode=changemaster mode: changemaster
master_host={{ mariadb_replication_host }} master_host: "{{ mariadb_replication_host }}"
master_port={{ mariadb_replication_port }} master_port: "{{ mariadb_replication_port }}"
master_user={{ mariadb_replication_user }} master_user: "{{ mariadb_replication_user }}"
master_password={{ mariadb_replication_password }} master_password: "{{ mariadb_replication_password }}"
- name: MYSQL_REPLICATION | Change master - name: MYSQL_REPLICATION | Change master
mysql_replication: > mysql_replication:
mode=changemaster mode: changemaster
master_log_file={{ mariadb_master_log_file }} master_log_file: "{{ mariadb_master_log_file }}"
master_log_pos={{ mariadb_master_log_pos }} master_log_pos: "{{ mariadb_master_log_pos }}"
when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined
- name: MYSQL_REPLICATION | Start slave - name: MYSQL_REPLICATION | Start slave
mysql_replication: mode=startslave mysql_replication:
mode: startslave

View File

@ -1,7 +1,10 @@
--- ---
- name: MYSQL_USER | Update mysql root password for all root accounts - name: MYSQL_USER | Update mysql root password for all root accounts
mysql_user: name=root host={{ item }} password={{ mariadb_root_password }} mysql_user:
name: root
host: "{{ item }}"
password: "{{ mariadb_root_password }}"
with_items: with_items:
- "{{ ansible_hostname }}" - "{{ ansible_hostname }}"
- 127.0.0.1 - 127.0.0.1
@ -9,7 +12,10 @@
- localhost - localhost
- name: MYSQL_USER | Remove all anonymous users - name: MYSQL_USER | Remove all anonymous users
mysql_user: name='' host={{ item }} state=absent mysql_user:
name: ''
host: "{{ item }}"
state: absent
with_items: with_items:
- "{{ ansible_hostname }}" - "{{ ansible_hostname }}"
- 127.0.0.1 - 127.0.0.1
@ -17,5 +23,6 @@
- localhost - localhost
- name: MYSQL_DB | Remove the test database - name: MYSQL_DB | Remove the test database
mysql_db: name=test state=absent mysql_db:
name: test
state: absent

View File

@ -2,5 +2,5 @@
Explanation: Prevent Debian upgrades on mariadb packages Explanation: Prevent Debian upgrades on mariadb packages
Package: * Package: *
Pin: origin {{ mariadb_mariadb_mirror_domain }} Pin: origin {{ mariadb_mirror_domain }}
Pin-Priority: 1000 Pin-Priority: 1000

View File

@ -49,7 +49,7 @@
vars: vars:
mariadb_galera_primary_node: '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-mariadbgalera-1' mariadb_galera_primary_node: '{% if is_docker %}docker-{% else %}vbox-{% endif %}{{ ansible_distribution_release }}-upstream-mariadbgalera-1'
mariadb_wsrep_node_address: "{{ ansible_all_ipv4_addresses[0] }}" mariadb_wsrep_node_address: "{{ ansible_all_ipv4_addresses[0] }}"
mariadb_mariadb_version: '10.1' mariadb_version: '10.1'
pre_tasks: pre_tasks:
- set_fact: - set_fact:
mariadb_wsrep_node_address: "{{ ansible_eth1.ipv4.address }}" mariadb_wsrep_node_address: "{{ ansible_eth1.ipv4.address }}"