Skip to content

Instantly share code, notes, and snippets.

@lihongjie0209
Created July 17, 2020 08:51
Show Gist options
  • Save lihongjie0209/93f4a94cbc629a55296ac15d8dc354f6 to your computer and use it in GitHub Desktop.
Save lihongjie0209/93f4a94cbc629a55296ac15d8dc354f6 to your computer and use it in GitHub Desktop.
安装mysql的ansible脚本
---
- hosts: all
tasks:
- name: disable selinux
selinux:
state: disabled
- name: disable firewalld
service:
name: firewalld
state: stopped
enabled: no
- name: install mysql repo
copy:
content: |
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
dest: /etc/yum.repos.d/mysql.repo
- name: install mysql server
yum:
name: mysql-server
state: present
update_cache: yes
- name: enable and start mysqld
service:
name: mysqld
state: started
enabled: yes
- name: update mysql password
shell: >
mysql -u root -p$(sed -n -r '/password/s/.+: (.+)$/\1/p' /var/log/mysqld.log | head -1) -e
"SET GLOBAL validate_password_length = 6; SET GLOBAL validate_password_number_count = 0;SET GLOBAL validate_password_policy=LOW; ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';"
--connect-expired-password
ignore_errors: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment