#centos7
---
- hosts: 10.0.0.27
remote_user: root
gather_facts: no
tasks:
- name: "创建Mysql用户"
shell: id mysql &> /dev/null || useradd -r -d /data/mysql -s /sbin/nologin mysql
- name: "安装依赖包"
yum: name=libaio,perl-Data-Dumper,ncurses-libs
- name: "创建mysql的家目录文件夹"
file: path=/data/mysql state=directory owner=mysql group=mysql
- name: "解压二进制程序"
unarchive: src=/data/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz dest=/usr/local owner=root group=root
- name: "将压缩后的文件设置为软链接"
file: src=/usr/local/mysql-8.0.19-linux-glibc2.12-x86_64 dest=/usr/local/mysql state=link
- name: "环境变量"
copy: content='PATH=/usr/local/mysql/bin/:$PATH' dest=/etc/profile.d/mysql.sh
- name: "同步环境变量"
shell: source /etc/profile.d/mysql.sh
- name: "准备MySQL配置文件"
copy: content='[mysqld]
datadir = /data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
port=3306
socket=/data/mysql/mysql.sock
' dest=/etc/my.cnf
- name: "生成数据库文件"
shell: /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql
- name: "复制服务启动文件"
shell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- name: "启动mysql服务并设置开机启动"
shell: chkconfig --add mysqld;chkconfig mysqld on;service mysqld start
- name: "修改mysql默认密码"
shell: mysqladmin -uroot -p`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log` password 123456
#centos8
---
- hosts: 10.0.0.58
remote_user: root
gather_facts: no
tasks:
- name: "创建Mysql用户"
shell: id mysql &> /dev/null || useradd -r -d /data/mysql -s /sbin/nologin mysql
- name: "安装依赖包"
yum: name=libaio,perl-Data-Dumper,ncurses-c++-libs,ncurses-compat-libs
- name: "创建mysql的家目录文件夹"
file: path=/data/mysql state=directory owner=mysql group=mysql
- name: "解压二进制程序"
unarchive: src=/data/mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz dest=/usr/local owner=root group=root
- name: "将压缩后的文件设置为软链接"
file: src=/usr/local/mysql-8.0.19-linux-glibc2.12-x86_64 dest=/usr/local/mysql state=link
- name: "环境变量"
copy: content='PATH=/usr/local/mysql/bin/:$PATH' dest=/etc/profile.d/mysql.sh
- name: "同步环境变量"
shell: source /etc/profile.d/mysql.sh
- name: "准备MySQL配置文件"
copy: content='[mysqld]
datadir = /data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
port=3306
socket=/data/mysql/mysql.sock
' dest=/etc/my.cnf
- name: "生成数据库文件"
shell: /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql
- name: "复制服务启动文件"
shell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- name: "启动mysql服务并设置开机启动"
shell: chkconfig --add mysqld;chkconfig mysqld on;service mysqld start
- name: "修改mysql默认密码"
shell: mysqladmin -uroot -p`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log` password 123456