117 lines
4.4 KiB
YAML
117 lines
4.4 KiB
YAML
- block:
|
|
- name: Check if the Mariadb service already exists
|
|
shell: rpm -qa | grep MariaDB | wc -l
|
|
register: check_out
|
|
- name: copy unload_mariadb.sh to {{ install_path }}/
|
|
template:
|
|
src: 'unload_mariadb.sh.j2'
|
|
dest: '{{ install_path }}/unload_mariadb.sh'
|
|
force: true
|
|
mode: 0755
|
|
when: check_out.stdout >= '1'
|
|
- name: unload mariadb
|
|
shell: cd {{ install_path }} && sh unload_mariadb.sh
|
|
when: check_out.stdout >= '1'
|
|
- name: Ansible delete {{ install_path }}/unload_mariadb.sh
|
|
file:
|
|
path: "{{ install_path }}/unload_mariadb.sh"
|
|
state: absent
|
|
- name: Check if the Mariadb service already exists
|
|
shell: rpm -qa | grep MariaDB | wc -l
|
|
register: check_out
|
|
- name: To terminate execution
|
|
fail:
|
|
msg: "卸载失败,组件可能非本安装部署,请手动卸载后继续安装"
|
|
run_once: true
|
|
delegate_to: 127.0.0.1
|
|
when: check_out.stdout >= '1'
|
|
when: (allowed_unload) == "yes"
|
|
|
|
- block:
|
|
- name: Check if the Mariadb service already exists
|
|
shell: rpm -qa | grep MariaDB | wc -l
|
|
register: check_out
|
|
- name: To terminate execution
|
|
fail:
|
|
msg: "检测到目标集群内已有Mariadb请检查IP是否正确或停止/卸载已启动的组件"
|
|
run_once: true
|
|
delegate_to: 127.0.0.1
|
|
when: check_out.stdout >= '1'
|
|
when: (allowed_unload) == "no"
|
|
|
|
- name: check mariadb version; if mariadb does not exist, it will be print error;Don't Worry!!!
|
|
shell: mysql -uroot
|
|
ignore_errors: True
|
|
register: result
|
|
|
|
- name: create directory path:/data/mariadb/logs
|
|
file:
|
|
state: directory
|
|
path: '/data/mariadb/logs'
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: create directory path:/data/mariadb/sql
|
|
file:
|
|
state: directory
|
|
path: '/data/mariadb/sql'
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: create directory path:{{ install_path }}/mariadb/sql
|
|
file:
|
|
state: directory
|
|
path: '{{ install_path }}/mariadb'
|
|
when: result.stderr is defined and result.stderr != ''
|
|
|
|
- name: copy
|
|
copy: src=files/slow_query.log dest=/data/mariadb/logs force=true backup=yes
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: mariadb service not exist; copy -rpm.zip and unzip mariadb.zip to {{ install_path }}/mariadb
|
|
unarchive: src={{ package_path }}/mariadb.zip dest={{ install_path }}/mariadb copy=yes
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: mariadb service not exist; install mariadb
|
|
shell: rpm -ivh {{ install_path }}/mariadb/*.rpm --force --nodeps && systemctl start mysql && systemctl enable mysql
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
register: install_mariadb_result
|
|
|
|
- name: copy my.cnf
|
|
template:
|
|
src: my.cnf_master.j2
|
|
dest: '/etc/my.cnf'
|
|
force: yes
|
|
run_once: true
|
|
delegate_to: '{{ groups.mariadb[0] }}'
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: copy my.cnf
|
|
template:
|
|
src: my.cnf_slave.j2
|
|
dest: '/etc/my.cnf'
|
|
force: yes
|
|
run_once: true
|
|
delegate_to: '{{ groups.mariadb[1] }}'
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: change mariadb root password
|
|
shell: mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '{{ galaxy_mariadb_pin }}';"
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: change mariadb remote authority
|
|
shell: mysql -uroot -p{{ galaxy_mariadb_pin }} -e"use mysql;grant all privileges on *.* to 'root'@'%' identified by '{{ galaxy_mariadb_pin }}' with grant option;FLUSH PRIVILEGES;"
|
|
when: result.stderr is defined and result.stderr != '' #有错误信息,说明mariadb服务不存在
|
|
|
|
- name: restart mariadb
|
|
shell: systemctl restart mysql
|
|
|
|
- name: copy {{ install_path }}/mariadb up_mysql.sh
|
|
template:
|
|
src: up_mysql.sh.j2
|
|
dest: '{{ install_path }}/mariadb/up_mysql.sh'
|
|
mode: 755
|
|
backup: yes
|
|
|
|
- name: start {{ install_path }}/mariadb up_mysql.sh
|
|
shell: cd {{ install_path }}/mariadb && ./up_mysql.sh
|
|
register: command_result
|