Ansible Playbook for Bulk MySQL 8.0 Deployment Across Multiple Nodes
This article shares an Ansible playbook that automates the installation and configuration of MySQL 8.0 on a large set of database servers, while also encouraging readers to share the content for broader community benefit.
The author invites readers to follow the "DevOps Architecture Practice" account, share the post to their moments, and promises daily technical content at 07:30, emphasizing community engagement and personal growth.
For large‑scale batch deployments, tools like Ansible or shell scripts are recommended; the author references previous shell script tutorials for system initialization.
A sample Ansible playbook (install_mysql.yml) is provided to deploy MySQL 8.0 on hosts db01‑db50, covering tasks such as installing the package, creating users and groups, setting up directories, extracting binaries, configuring the service, and initializing the database.
---
- hosts: db[01-50]
remote_user: root
gather_facts: no
tasks:
- name: del mariadb
shell: yum -y install mariadb*
- name: create group
group: name=mysql system=yes
- name: create user mysql
user: name=mysql system=yes group=mysql shell=/sbin/nologin
- name: create mysql datadir
file: path=/data/mysql/mysql owner=mysql group=mysql state=directory
- name: unarchive mysql package
unarchive: src=/root/mysql-8.0.17-linux-glibc2.12-x86_64.tar.gz dest=/usr/local owner=root group=root
- name: move unarchive mysql
shell: mv /usr/local/mysql* /usr/local/mysql
- name: config
copy: src=/root/my.cnf dest=/etc/ backup=yes
- name: initialize mysql
shell: /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql
args:
chdir: /usr/local/mysql
- name: script
copy: src=/usr/local/mysql/support-files/mysql.server dest=/etc/init.d/mysqld mode=755
- name: mysql start
shell: /etc/init.d/mysqld start
- name: PATH var
copy: content='PATH=/usr/local/mysql/bin:$PATH' dest=/etc/profile.d/mysql.sh
- name: source script
shell: source /etc/profile.d/mysql.shRecommended reading links are provided for deeper dives into Kubernetes MySQL deployment, stateless app deployment, elastic scaling, dashboard setup, and NFS persistent storage.
Please share the article to your moments; each share contributes to the success of the community.
Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.