Добавить ansible.yml
This commit is contained in:
113
ansible.yml
Normal file
113
ansible.yml
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
- hosts: all
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
|
||||||
|
- name: update
|
||||||
|
apt:
|
||||||
|
update_cache: yes
|
||||||
|
|
||||||
|
- name: install mysql
|
||||||
|
apt:
|
||||||
|
name: mysql-server
|
||||||
|
|
||||||
|
- name: copy mysql dump
|
||||||
|
copy:
|
||||||
|
src: bet.dmp
|
||||||
|
dest: /tmp/bet.dmp
|
||||||
|
|
||||||
|
- name: create db
|
||||||
|
shell: mysql -e "CREATE DATABASE IF NOT EXISTS bet;"
|
||||||
|
|
||||||
|
- name: create user replication
|
||||||
|
shell: mysql -e "CREATE USER IF NOT EXISTS 'replication'@'%' IDENTIFIED BY 'mySyperPass';"
|
||||||
|
when: ansible_hostname == "mysql-master"
|
||||||
|
|
||||||
|
- name: replication allow user
|
||||||
|
shell: mysql -e "GRANT REPLICATION SLAVE ON *.* TO 'replication'@'%';"
|
||||||
|
when: ansible_hostname == "mysql-master"
|
||||||
|
|
||||||
|
- name: change bind-address mysql-master
|
||||||
|
lineinfile:
|
||||||
|
path: /etc/mysql/mysql.conf.d/mysqld.cnf
|
||||||
|
regexp: "^bind-address.*"
|
||||||
|
line: 'bind-address = 0.0.0.0'
|
||||||
|
when: ansible_hostname == "mysql-master"
|
||||||
|
|
||||||
|
- name: upload dump mysql-master
|
||||||
|
shell: mysql bet < /tmp/bet.dmp
|
||||||
|
when: ansible_hostname == "mysql-master"
|
||||||
|
|
||||||
|
- name: conf replication mysql-master
|
||||||
|
blockinfile:
|
||||||
|
path: /etc/mysql/mysql.conf.d/mysqld.cnf
|
||||||
|
block: |
|
||||||
|
server-id=1
|
||||||
|
gtid-mode=ON
|
||||||
|
enforce-gtid-consistency
|
||||||
|
log-replica-updates
|
||||||
|
when: ansible_hostname == "mysql-master"
|
||||||
|
|
||||||
|
- name: restart mysql
|
||||||
|
systemd:
|
||||||
|
name: mysql
|
||||||
|
state: restarted
|
||||||
|
when: ansible_hostname == "mysql-master"
|
||||||
|
|
||||||
|
- name: create temp db
|
||||||
|
shell: mysql -e "CREATE DATABASE IF NOT EXISTS temp_bet;"
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: upload dump to temp db
|
||||||
|
shell: mysql temp_bet < /tmp/bet.dmp
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: dump the required tables
|
||||||
|
shell: mysqldump temp_bet bookmaker competition market odds outcome > /tmp/bet_new.sql
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: upload dump
|
||||||
|
shell: mysql bet < /tmp/bet_new.sql
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: drop temp db
|
||||||
|
shell: mysql -e "DROP DATABASE temp_bet;"
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: conf replication mysql-slave
|
||||||
|
blockinfile:
|
||||||
|
path: /etc/mysql/mysql.conf.d/mysqld.cnf
|
||||||
|
block: |
|
||||||
|
server-id=2
|
||||||
|
gtid-mode=ON
|
||||||
|
enforce-gtid-consistency
|
||||||
|
log-replica-updates
|
||||||
|
replicate-do-table = bet.bookmaker
|
||||||
|
replicate-do-table = bet.competition
|
||||||
|
replicate-do-table = bet.market
|
||||||
|
replicate-do-table = bet.odds
|
||||||
|
replicate-do-table = bet.outcome
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: restart mysql
|
||||||
|
systemd:
|
||||||
|
name: mysql
|
||||||
|
state: restarted
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: enable replication
|
||||||
|
shell: |
|
||||||
|
mysql -e "CHANGE REPLICATION SOURCE TO
|
||||||
|
SOURCE_HOST = '192.168.50.10',
|
||||||
|
SOURCE_USER = 'replication',
|
||||||
|
SOURCE_PASSWORD = 'mySyperPass',
|
||||||
|
SOURCE_AUTO_POSITION = 1,
|
||||||
|
GET_SOURCE_PUBLIC_KEY = 1;"
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
- name: start replication mysql-slave
|
||||||
|
shell: mysql -e "START REPLICA;"
|
||||||
|
when: ansible_hostname == "mysql-slave"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user