154 lines
4.6 KiB
YAML
154 lines
4.6 KiB
YAML
|
|
- name: Setting node_nums variable
|
||
|
|
set_fact: node_nums={{ groups.mariadb|length }}
|
||
|
|
|
||
|
|
- name: To terminate execution
|
||
|
|
fail:
|
||
|
|
msg: "MariaDB in master-master mode. The value must have 2 nodes,please checking configurations/hosts -> mariadb"
|
||
|
|
when: node_nums != '2'
|
||
|
|
|
||
|
|
- name: Creating directory
|
||
|
|
file:
|
||
|
|
state: directory
|
||
|
|
owner: ods
|
||
|
|
group: root
|
||
|
|
path: '{{ deploy_dir }}/{{ container_name }}/{{ item.dir }}'
|
||
|
|
with_items:
|
||
|
|
- { dir: 'config' }
|
||
|
|
- { dir: 'logs' }
|
||
|
|
- { dir: 'monitor' }
|
||
|
|
|
||
|
|
- name: Copying image to {{ deploy_dir }}/{{ container_name }}/
|
||
|
|
copy:
|
||
|
|
src: 'files/{{ image_name }}-{{ image_tag }}.tar'
|
||
|
|
dest: '{{ deploy_dir }}/{{ container_name }}/'
|
||
|
|
force: true
|
||
|
|
notify:
|
||
|
|
- Loading Image
|
||
|
|
|
||
|
|
- name: Copying image to {{ deploy_dir }}/{{ container_name }}/monitor
|
||
|
|
copy:
|
||
|
|
src: 'files/mysqld_exporter-v1.0.tar'
|
||
|
|
dest: '{{ deploy_dir }}/{{ container_name }}/monitor/'
|
||
|
|
force: true
|
||
|
|
notify:
|
||
|
|
- Loading Exporter Image
|
||
|
|
|
||
|
|
- name: Copying Mariadb config files
|
||
|
|
template:
|
||
|
|
src: '{{ item.src }}'
|
||
|
|
dest: '{{ item.dest }}'
|
||
|
|
mode: 0644
|
||
|
|
with_items:
|
||
|
|
- { src: 'my.cnf.j2', dest: '{{ deploy_dir }}/{{ container_name }}/config/my.cnf' }
|
||
|
|
- { src: 'docker-compose.yml.j2', dest: '{{ deploy_dir }}/{{ container_name }}/docker-compose.yml' }
|
||
|
|
notify:
|
||
|
|
- Start Container
|
||
|
|
|
||
|
|
- meta: flush_handlers
|
||
|
|
|
||
|
|
- name: Waitting for MariaDB running,20s
|
||
|
|
shell: sleep 20
|
||
|
|
|
||
|
|
- name: Creating mariadb readonly user
|
||
|
|
shell: mysql -uroot -h{{ inventory_hostname }} -p{{ mariadb_default_pin }} -e "CREATE USER IF NOT EXISTS '{{ mariadb_query_username}}'@'%' IDENTIFIED BY '{{ mariadb_query_pin }}' WITH MAX_USER_CONNECTIONS 3;GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO '{{ mariadb_query_username}}'@'%';FLUSH PRIVILEGES;"
|
||
|
|
|
||
|
|
- name: change mariadb remote authority
|
||
|
|
shell: mysql -uroot -h{{ inventory_hostname }} -p{{ mariadb_default_pin }} -e"use mysql;grant all privileges on *.* to 'root'@'%' identified by '{{ mariadb_default_pin }}' with grant option;FLUSH PRIVILEGES;"
|
||
|
|
|
||
|
|
- name: copy pyMysql.zip
|
||
|
|
unarchive:
|
||
|
|
src: files/pyMysql.zip
|
||
|
|
dest: /tmp/
|
||
|
|
register: copy_info
|
||
|
|
|
||
|
|
- name: pip install pyMysql
|
||
|
|
shell: cd /tmp/pyMysql && pip install --ignore-installed *
|
||
|
|
when: copy_info.changed
|
||
|
|
|
||
|
|
- name: Get mariadb slave_status
|
||
|
|
mysql_info:
|
||
|
|
login_host: '{{ groups.mariadb[0] }}'
|
||
|
|
login_user: root
|
||
|
|
login_password: '{{ mariadb_default_pin }}'
|
||
|
|
filter: slave_status
|
||
|
|
register: mariadb_info
|
||
|
|
|
||
|
|
- name: change_slave_to_master1
|
||
|
|
mysql_replication:
|
||
|
|
login_unix_socket: "{{ deploy_dir }}/{{ container_name }}/data/mysql.sock"
|
||
|
|
login_host: "{{ groups.mariadb[1] }}"
|
||
|
|
login_port: "3306"
|
||
|
|
login_user: root
|
||
|
|
login_password: "{{ mariadb_default_pin }}"
|
||
|
|
master_host: "{{ groups.mariadb[0] }}"
|
||
|
|
master_user: root
|
||
|
|
master_password: "{{ mariadb_default_pin }}"
|
||
|
|
master_port: "3306"
|
||
|
|
mode: changemaster
|
||
|
|
run_once: true
|
||
|
|
delegate_to: '{{ groups.mariadb[1] }}'
|
||
|
|
tags:
|
||
|
|
- change_slave_to_master1
|
||
|
|
|
||
|
|
- name: start_slave1
|
||
|
|
mysql_replication:
|
||
|
|
login_unix_socket: "{{ deploy_dir }}/{{ container_name }}/data/mysql.sock"
|
||
|
|
login_user: root
|
||
|
|
login_host: "{{ inventory_hostname }}"
|
||
|
|
login_port: "3306"
|
||
|
|
login_password: "{{ mariadb_default_pin }}"
|
||
|
|
mode: startslave
|
||
|
|
tags:
|
||
|
|
- start_slave1
|
||
|
|
run_once: true
|
||
|
|
delegate_to: '{{ groups.mariadb[1] }}'
|
||
|
|
|
||
|
|
- name: change_slave_to_master2
|
||
|
|
mysql_replication:
|
||
|
|
login_unix_socket: "{{ deploy_dir }}/{{ container_name }}/data/mysql.sock"
|
||
|
|
login_host: "{{ groups.mariadb[0] }}"
|
||
|
|
login_port: "3306"
|
||
|
|
login_user: root
|
||
|
|
login_password: "{{ mariadb_default_pin }}"
|
||
|
|
master_host: "{{ groups.mariadb[1] }}"
|
||
|
|
master_user: root
|
||
|
|
master_password: "{{ mariadb_default_pin }}"
|
||
|
|
master_port: "3306"
|
||
|
|
mode: changemaster
|
||
|
|
run_once: true
|
||
|
|
delegate_to: '{{ groups.mariadb[0] }}'
|
||
|
|
tags:
|
||
|
|
- change_slave_to_master2
|
||
|
|
|
||
|
|
- name: start_slave2
|
||
|
|
mysql_replication:
|
||
|
|
login_unix_socket: "{{ deploy_dir }}/{{ container_name }}/data/mysql.sock"
|
||
|
|
login_user: root
|
||
|
|
login_host: "{{ inventory_hostname }}"
|
||
|
|
login_port: "3306"
|
||
|
|
login_password: "{{ mariadb_default_pin }}"
|
||
|
|
mode: startslave
|
||
|
|
tags:
|
||
|
|
- start_slave2
|
||
|
|
run_once: true
|
||
|
|
delegate_to: '{{ groups.mariadb[0] }}'
|
||
|
|
|
||
|
|
- name: get_slave_info
|
||
|
|
mysql_replication:
|
||
|
|
login_host: 127.0.0.1
|
||
|
|
login_user: root
|
||
|
|
login_port: "3306"
|
||
|
|
login_password: "{{ mariadb_default_pin }}"
|
||
|
|
mode: getslave
|
||
|
|
register: info
|
||
|
|
tags:
|
||
|
|
- get_slave_info
|
||
|
|
|
||
|
|
- name: Copying Mariadb config files
|
||
|
|
template:
|
||
|
|
src: 'exporter_docker-compose.yml.j2'
|
||
|
|
dest: '{{ deploy_dir }}/{{ container_name }}/monitor/docker-compose.yml'
|
||
|
|
mode: 0644
|
||
|
|
notify:
|
||
|
|
- Start Exporter Container
|