Better code display
parent
c72c3ac842
commit
cc3bef8bfa
|
@ -1,7 +1,9 @@
|
|||
---
|
||||
|
||||
- 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
|
||||
|
||||
- name: INCLUDE | Bootstrap first node
|
||||
|
@ -13,7 +15,9 @@
|
|||
when: inventory_hostname != mariadb_galera_primary_node
|
||||
|
||||
- name: SERVICE | Restart MariaDB if needed
|
||||
service: name=mysql state=restarted
|
||||
service:
|
||||
name: mysql
|
||||
state: restarted
|
||||
when: >
|
||||
((galeraconfig or (p is defined and p.changed)) and
|
||||
(bootstrap_run is not defined)) or
|
||||
|
|
|
@ -14,18 +14,22 @@
|
|||
- block:
|
||||
|
||||
- name: SERVICE | Stop MariaDB
|
||||
service: name=mysql state=stopped
|
||||
service:
|
||||
name: mysql
|
||||
state: stopped
|
||||
|
||||
- name: COPY | Paste primary node's debian.cnf
|
||||
copy: >
|
||||
content={{ debiancnf.stdout }}
|
||||
dest=/etc/mysql/debian.cnf
|
||||
mode=0600
|
||||
owner=root
|
||||
group=root
|
||||
copy:
|
||||
content: "{{ debiancnf.stdout }}"
|
||||
dest: /etc/mysql/debian.cnf
|
||||
mode: 0600
|
||||
owner: root
|
||||
group: root
|
||||
register: paste
|
||||
|
||||
- name: SERVICE | Start MariaDB
|
||||
service: name=mysql state=started
|
||||
service:
|
||||
name: mysql
|
||||
state: started
|
||||
|
||||
when: debiancnf.stdout != ondc.stdout
|
||||
|
|
|
@ -1,21 +1,31 @@
|
|||
---
|
||||
|
||||
- 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
|
||||
changed_when: false
|
||||
|
||||
- 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
|
||||
|
||||
- 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
|
||||
|
||||
- name: APT | Install MariaDB server
|
||||
apt: pkg=mariadb-server state=present
|
||||
apt:
|
||||
pkg: mariadb-server
|
||||
|
||||
- name: APT | Install Galera
|
||||
apt: pkg=galera-3 state=present
|
||||
apt:
|
||||
pkg: galera-3
|
||||
when: mariadb_vendor == 'mariadb_galera'
|
||||
|
|
|
@ -1,17 +1,23 @@
|
|||
---
|
||||
|
||||
- name: APT_KEY | Install MariaDB key
|
||||
apt_key: keyserver="{{ mariadb_mariadb_key_server }}" id={{ item }} state=present
|
||||
with_items: "{{ mariadb_mariadb_key_ids }}"
|
||||
apt_key:
|
||||
keyserver: "{{ mariadb_key_server }}"
|
||||
id: "{{ item }}"
|
||||
with_items: "{{ mariadb_key_ids }}"
|
||||
|
||||
- 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
|
||||
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
|
||||
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
|
||||
|
||||
- name: INCLUDE | Normal Install
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
---
|
||||
|
||||
- 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)
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
|
|
|
@ -13,21 +13,33 @@
|
|||
include: install/main.yml
|
||||
|
||||
- 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
|
||||
|
||||
- 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
|
||||
|
||||
- name: SERVICE | Restart now (prevent bugs)
|
||||
service: name=mysql state=restarted
|
||||
service:
|
||||
name: mysql
|
||||
state: restarted
|
||||
when: >
|
||||
(config.changed or extraconfig.changed) and
|
||||
not mariadb_galera_resetup
|
||||
|
||||
- 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
|
||||
include: galera/main.yml
|
||||
|
@ -41,19 +53,23 @@
|
|||
include: 'secure.yml'
|
||||
|
||||
- name: SERVICE | Ensure service is started
|
||||
service: name=mysql state=started
|
||||
service:
|
||||
name: mysql
|
||||
state: started
|
||||
|
||||
- name: MYSQL_DB | Create databases
|
||||
mysql_db: name={{ item }} state=present
|
||||
mysql_db:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
with_items: "{{ mariadb_databases }}"
|
||||
|
||||
- name: MYSQL_USER | Manages users...
|
||||
mysql_user: >
|
||||
name="{{ item.name }}"
|
||||
password="{{ item.password }}"
|
||||
priv="{{ item.priv }}"
|
||||
host="{{ item.host | default('localhost') }}"
|
||||
state=present
|
||||
mysql_user:
|
||||
name: "{{ item.name }}"
|
||||
password: "{{ item.password }}"
|
||||
priv: "{{ item.priv }}"
|
||||
host: "{{ item.host | default('localhost') }}"
|
||||
state: present
|
||||
with_items: "{{ mariadb_users }}"
|
||||
|
||||
- name: TEMPLATE | Deploy logrotate configuration
|
||||
|
|
|
@ -7,4 +7,3 @@
|
|||
- name: INCLUDE | Replication slave
|
||||
include: slave.yml
|
||||
when: mariadb_replication_slave
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
|
||||
- name: TEMPLATE | Deploy master configuration
|
||||
template: >
|
||||
src=etc/mysql/conf.d/50-master.cnf.j2
|
||||
dest=/etc/mysql/conf.d/50-master.cnf
|
||||
template:
|
||||
src: etc/mysql/conf.d/50-master.cnf.j2
|
||||
dest: /etc/mysql/conf.d/50-master.cnf
|
||||
notify: restart mariadb
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
---
|
||||
|
||||
- name: MYSQL_VARIABLES | Set read only
|
||||
mysql_variables: variable=read_only value=ON
|
||||
mysql_variables:
|
||||
variable: read_only
|
||||
value: 'ON'
|
||||
when: mariadb_slave_readonly
|
||||
|
||||
- name: TEMPLATE | Deploy slave configuration
|
||||
template: >
|
||||
src=etc/mysql/conf.d/51-slave.cnf.j2
|
||||
dest=/etc/mysql/conf.d/51-slave.cnf
|
||||
template:
|
||||
src: etc/mysql/conf.d/51-slave.cnf.j2
|
||||
dest: /etc/mysql/conf.d/51-slave.cnf
|
||||
notify: restart mariadb
|
||||
|
||||
- name: MYSQL_REPLICATION | Get slave status
|
||||
mysql_replication: mode=getslave
|
||||
mysql_replication:
|
||||
mode: getslave
|
||||
ignore_errors: yes
|
||||
register: slave_status
|
||||
|
||||
|
@ -32,7 +35,8 @@
|
|||
when: mariadb_slave_replicate_mysqldb
|
||||
|
||||
- name: MYSQL_REPLICATION | Get slave status
|
||||
mysql_replication: mode=getslave
|
||||
mysql_replication:
|
||||
mode: getslave
|
||||
ignore_errors: yes
|
||||
register: slave_status
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
---
|
||||
|
||||
- name: FETCH | Get /etc/mysql/debian.cnf on master
|
||||
fetch: >
|
||||
src=/etc/mysql/debian.cnf
|
||||
dest=/tmp/{{ mariadb_slave_import_from }}/debian.cnf
|
||||
flat=yes
|
||||
fetch:
|
||||
src: /etc/mysql/debian.cnf
|
||||
dest: /tmp/{{ mariadb_slave_import_from }}/debian.cnf
|
||||
flat: yes
|
||||
changed_when: false
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
|
||||
|
@ -13,9 +13,10 @@
|
|||
become: no
|
||||
|
||||
- name: COPY | Fetched file to /etc/mysql/debian.cnf
|
||||
copy: >
|
||||
src=/tmp/{{ mariadb_slave_import_from }}/debian.cnf
|
||||
dest=/etc/mysql/debian.cnf
|
||||
owner=root group=root mode=0600
|
||||
copy:
|
||||
src: "/tmp/{{ mariadb_slave_import_from }}/debian.cnf"
|
||||
dest: /etc/mysql/debian.cnf
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0600
|
||||
notify: restart mariadb
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
# 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
|
||||
wait_for: host={{ mariadb_slave_import_from }} port=22
|
||||
wait_for:
|
||||
host: "{{ mariadb_slave_import_from }}"
|
||||
port: 22
|
||||
|
||||
- name: COMMAND | Prepare backup another server
|
||||
command: innobackupex --no-timestamp {{ mariadb_backup_dir }} creates={{ mariadb_backup_dir }}
|
||||
|
@ -10,12 +12,14 @@
|
|||
register: backup
|
||||
|
||||
- name: SHELL | Dump
|
||||
shell: innobackupex --apply-log {{ mariadb_backup_dir }}
|
||||
shell: "innobackupex --apply-log {{ mariadb_backup_dir }}"
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
when: backup.changed
|
||||
|
||||
- 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 }}"
|
||||
when: backup.changed and not mariadb_slave_replicate_mysqldb
|
||||
|
||||
|
@ -25,38 +29,42 @@
|
|||
|
||||
- name: SET_FACT | related to mysql datadir
|
||||
set_fact:
|
||||
mariadb_mariadb_datadir: "{{ datadir.msg }}"
|
||||
mariadb_datadir: "{{ datadir.msg }}"
|
||||
mariadb_binlog_info: "{{ datadir.msg }}/xtrabackup_binlog_info"
|
||||
|
||||
- name: SERVICE | Stop MySQL before importing data
|
||||
service: name=mysql state=stopped
|
||||
service:
|
||||
name: mysql
|
||||
state: stopped
|
||||
|
||||
# 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)
|
||||
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
|
||||
|
||||
- name: FILE | Re-apply owner
|
||||
file: >
|
||||
path={{ mariadb_mariadb_datadir }}
|
||||
state=directory
|
||||
owner=mysql
|
||||
group=mysql
|
||||
recurse=yes
|
||||
file:
|
||||
path: "{{ mariadb_datadir }}"
|
||||
state: directory
|
||||
owner: mysql
|
||||
group: mysql
|
||||
recurse: yes
|
||||
|
||||
- name: SERVICE | Start MySQL
|
||||
service: name=mysql state=started
|
||||
- name: SERVICE | Start MariaDB
|
||||
service:
|
||||
name: mysql
|
||||
state: started
|
||||
|
||||
- name: SHELL | Get master_log_file
|
||||
command: awk '{ print $1 }' {{ mariadb_binlog_info }}
|
||||
command: "awk '{ print $1 }' {{ mariadb_binlog_info }}"
|
||||
register: master_log_file
|
||||
|
||||
- name: SHELL | Get master_log_pos
|
||||
command: awk '{ print $2 }' {{ mariadb_binlog_info }}
|
||||
command: "awk '{ print $2 }' {{ mariadb_binlog_info }}"
|
||||
register: master_log_pos
|
||||
|
||||
- name: SHELL | Get master GTID
|
||||
command: awk '{ print $3 }' {{ mariadb_binlog_info }}
|
||||
command: "awk '{ print $3 }' {{ mariadb_binlog_info }}"
|
||||
register: master_gtid
|
||||
|
||||
- name: SET_FACT | master_log_file
|
||||
|
@ -69,4 +77,3 @@
|
|||
file: path={{ mariadb_backup_dir }} state=absent
|
||||
delegate_to: "{{ mariadb_slave_import_from }}"
|
||||
when: mariadb_slave_import_flush_dump
|
||||
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
# - https://mariadb.com/kb/en/mariadb/global-transaction-id/#switching-an-existing-old-style-slave-to-use-gtid
|
||||
|
||||
- name: MYSQL_REPLICATION | Stop slave
|
||||
mysql_replication: mode=stopslave
|
||||
mysql_replication:
|
||||
mode: stopslave
|
||||
|
||||
- name: COMMAND | Migrate to MariaDB GTID
|
||||
command: mysql -e "CHANGE MASTER TO master_use_gtid=current_pos";
|
||||
|
||||
- name: MYSQL_REPLICATION | Start slave
|
||||
mysql_replication: mode=startslave
|
||||
mysql_replication:
|
||||
mode: startslave
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
---
|
||||
|
||||
- name: MYSQL_REPLICATION | Stop slave
|
||||
mysql_replication: mode=stopslave
|
||||
mysql_replication:
|
||||
mode: stopslave
|
||||
|
||||
- name: MYSQL_REPLICATION | Configure master host
|
||||
mysql_replication: >
|
||||
mode=changemaster
|
||||
master_host={{ mariadb_replication_host }}
|
||||
master_port={{ mariadb_replication_port }}
|
||||
master_user={{ mariadb_replication_user }}
|
||||
master_password={{ mariadb_replication_password }}
|
||||
mysql_replication:
|
||||
mode: changemaster
|
||||
master_host: "{{ mariadb_replication_host }}"
|
||||
master_port: "{{ mariadb_replication_port }}"
|
||||
master_user: "{{ mariadb_replication_user }}"
|
||||
master_password: "{{ mariadb_replication_password }}"
|
||||
|
||||
- name: MYSQL_REPLICATION | Change master
|
||||
mysql_replication: >
|
||||
mode=changemaster
|
||||
master_log_file={{ mariadb_master_log_file }}
|
||||
master_log_pos={{ mariadb_master_log_pos }}
|
||||
mysql_replication:
|
||||
mode: changemaster
|
||||
master_log_file: "{{ mariadb_master_log_file }}"
|
||||
master_log_pos: "{{ mariadb_master_log_pos }}"
|
||||
when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined
|
||||
|
||||
- name: MYSQL_REPLICATION | Start slave
|
||||
mysql_replication: mode=startslave
|
||||
mysql_replication:
|
||||
mode: startslave
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
---
|
||||
|
||||
- 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:
|
||||
- "{{ ansible_hostname }}"
|
||||
- 127.0.0.1
|
||||
|
@ -9,7 +12,10 @@
|
|||
- localhost
|
||||
|
||||
- name: MYSQL_USER | Remove all anonymous users
|
||||
mysql_user: name='' host={{ item }} state=absent
|
||||
mysql_user:
|
||||
name: ''
|
||||
host: "{{ item }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- "{{ ansible_hostname }}"
|
||||
- 127.0.0.1
|
||||
|
@ -17,5 +23,6 @@
|
|||
- localhost
|
||||
|
||||
- name: MYSQL_DB | Remove the test database
|
||||
mysql_db: name=test state=absent
|
||||
|
||||
mysql_db:
|
||||
name: test
|
||||
state: absent
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
Explanation: Prevent Debian upgrades on mariadb packages
|
||||
Package: *
|
||||
Pin: origin {{ mariadb_mariadb_mirror_domain }}
|
||||
Pin: origin {{ mariadb_mirror_domain }}
|
||||
Pin-Priority: 1000
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
vars:
|
||||
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_mariadb_version: '10.1'
|
||||
mariadb_version: '10.1'
|
||||
pre_tasks:
|
||||
- set_fact:
|
||||
mariadb_wsrep_node_address: "{{ ansible_eth1.ipv4.address }}"
|
||||
|
|
Loading…
Reference in New Issue