From 2dcb4da188431e23becd5dc95a05367844a9a666 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 26 Apr 2026 00:13:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20ansible.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ansible.yml | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 ansible.yml diff --git a/ansible.yml b/ansible.yml new file mode 100644 index 0000000..6a439a6 --- /dev/null +++ b/ansible.yml @@ -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" + + + +