Step-by-Step Guide to Deploy MySQL Using Ansible Roles
This tutorial walks through creating an Ansible role that structures directories, defines configuration templates, sets variables, writes task files, and runs a playbook to install MySQL 8.0.32 on a Linux host, illustrating a complete automation workflow for database deployment.
The article demonstrates how to build an Ansible role for installing MySQL 8.0.32 on a Linux server, covering directory layout, template creation, variable definition, task implementation, and playbook execution.
First, a standard role directory is created with
mkdir -p mysql/{default,files,handlers,meta,tasks,templates,vars}and the resulting tree looks like:
mysql
├── default
├── files
│ └── mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
├── handlers
├── meta
├── tasks
│ ├── copy.yml
│ ├── install.yml
│ └── main.yml
├── templates
│ ├── my.cnf.j2
│ └── mysql_install.sh.j2
└── vars
└── main.ymlIn the templates folder, two Jinja2 files are added: my.cnf.j2 for MySQL configuration and mysql_install.sh.j2 for the installation script.
The role is invoked from a playbook mysql_install.yml:
---
- hosts: ms
remote_user: root
roles:
- role: mysqlVariable values are stored in vars/main.yml:
mysql_version: mysql-8.0.32-linux-glibc2.12-x86_64
install_dir: /usr/local/mysql
data_dir: /data/mysql/mysql
source_dir: /tmpTask files are created under tasks. install.yml runs the installation script:
- name: install mysql
shell: bash {{source_dir}}/mysql_install.shThe tasks/main.yml includes the copy and install tasks:
- include: copy.yml
- include: install.ymlFinally, the role is tested with a dry‑run command: ansible-playbook -C mysql_install.yml Overall, the guide provides a reproducible, modular approach to automate MySQL deployment using Ansible.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
