部署mariadb数据库主从
配置主机清单
[root@ansible ansible]# vim hosts
[mysql]
node4
node5
[mysql_master]
node4
[mysql_slave]
node5
创建角色
[root@ansible roles]# ansible-galaxy init mariadb
- Role mariadb was created successfully
编写任务
[root@ansible roles]# cd mariadb/
[root@ansible mariadb]# vim tasks/main.yml
---
# tasks file for mariadb
- name: rm repo
shell:
cmd: rm -rf /etc/yum.repos.d/*
- name: mount cdrom
mount:
src: /dev/sr0
path: /mnt
fstype: iso9660
state: mounted
- name: set repo1
yum_repository:
file: local
name: BaseOS
description: BaseOS
baseurl: file:///mnt/BaseOS
enabled: yes
gpgcheck: no
- name: set repo2
yum_repository:
file: local
name: AppStream
description: AppStream
baseurl: file:///mnt/AppStream
enabled: yes
gpgcheck: no
- name: install mariadb
yum:
name:
- mariadb
- mariadb-server
state: present
- name: modify config
template:
src: masterconfig.cnf.j2
dest: /etc/my.cnf
when: inventory_hostname in groups.mysql_master
- name: modify config2
template:
src: slaveconfig.cnf.j2
dest: /etc/my.cnf
when: inventory_hostname in groups.mysql_slave
- name: restart mariadb
service:
name: mariadb
state: restarted
enabled: yes
- name: stop firewalld
service:
name: firewalld
state: stopped
enabled: no
- name: stop selinux
lineinfile:
path: /etc/selinux/config
regexp: '^SELINUX='
line: SELINUX=disabled
- name: stop selinux1
shell:
cmd: setenforce 0
- name: mariadb grant
shell:
cmd: m