AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

ansible.mysql 5.0.0 Release: Migrate from community.mysql Collection

By Luca Berton · Published 2024-01-01 · Category: installation

ansible.mysql 5.0.0 released; community.mysql 4.2.1 is the last release. Migrate to ansible.mysql with this step-by-step guide.

Introduction

The ansible.mysql collection version 5.0.0 has been released, marking the official home for Ansible MySQL automation. Simultaneously, community.mysql 4.2.1 has been released as the last regular release of that collection — all future development continues in ansible.mysql.

If you're currently using community.mysql, now is the time to migrate.

See also: Ansible for Database Automation: PostgreSQL, MySQL, MongoDB, and Redis

What Changed?

ansible.mysql 5.0.0

This is a major version release indicating potential breaking changes from the community.mysql lineage: • New namespace: ansible.mysql replaces community.mysql • Module names remain the same (e.g., mysql_db, mysql_user, mysql_query) • Available on Ansible Galaxy

community.mysql 4.2.1 (Final Release)

• This is the last regular release of community.mysql • No new features will be added • Critical security fixes may still be backported for a limited time • All development moves to ansible.mysql

Migration Guide

Step 1: Install ansible.mysql

# Install the new collection
ansible-galaxy collection install ansible.mysql

# Verify installation ansible-galaxy collection list | grep ansible.mysql

Step 2: Update Collection Requirements

# requirements.yml
collections:
  - name: ansible.mysql
    version: ">=5.0.0"

# Remove or comment out: # - name: community.mysql

# Install from requirements
ansible-galaxy collection install -r requirements.yml

Step 3: Update Playbooks

Replace community.mysql with ansible.mysql in all your playbooks:

# Before (community.mysql)
- name: Create database
  community.mysql.mysql_db:
    name: my_database
    state: present

- name: Create user community.mysql.mysql_user: name: app_user password: "{{ vault_mysql_password }}" priv: "my_database.*:ALL" state: present

# After (ansible.mysql) - name: Create database ansible.mysql.mysql_db: name: my_database state: present

- name: Create user ansible.mysql.mysql_user: name: app_user password: "{{ vault_mysql_password }}" priv: "my_database.*:ALL" state: present

Step 4: Update Roles and Collections Dependencies

# meta/main.yml (in your roles)
dependencies: []

collections: - ansible.mysql

Step 5: Bulk Find and Replace

# Find all files using community.mysql
grep -r "community\.mysql" roles/ playbooks/ --include="*.yml" --include="*.yaml" -l

# Bulk replace (review changes before committing) find roles/ playbooks/ -name "*.yml" -o -name "*.yaml" | \ xargs sed -i 's/community\.mysql/ansible.mysql/g'

See also: Ansible for PostgreSQL and MySQL: Database Automation Complete Guide

Complete Playbook Example

---
- name: MySQL database automation with ansible.mysql
  hosts: database_servers
  become: true
  vars:
    mysql_root_password: "{{ vault_mysql_root_password }}"
    app_db_name: production_app
    app_db_user: app_service
    app_db_password: "{{ vault_app_db_password }}"

tasks: - name: Ensure MySQL is installed ansible.builtin.package: name: - mysql-server - python3-mysqlclient state: present

- name: Start and enable MySQL service ansible.builtin.service: name: mysqld state: started enabled: true

- name: Create application database ansible.mysql.mysql_db: name: "{{ app_db_name }}" state: present login_user: root login_password: "{{ mysql_root_password }}"

- name: Create application user with privileges ansible.mysql.mysql_user: name: "{{ app_db_user }}" password: "{{ app_db_password }}" priv: "{{ app_db_name }}.*:SELECT,INSERT,UPDATE,DELETE" host: "%" state: present login_user: root login_password: "{{ mysql_root_password }}"

- name: Run a query to verify setup ansible.mysql.mysql_query: query: "SHOW DATABASES LIKE '{{ app_db_name }}'" login_user: root login_password: "{{ mysql_root_password }}" register: db_check

- name: Display result ansible.builtin.debug: msg: "Database '{{ app_db_name }}' exists: {{ db_check.query_result | length > 0 }}"

Available Modules

The ansible.mysql collection includes:

| Module | Description | |---|---| | ansible.mysql.mysql_db | Add or remove MySQL databases | | ansible.mysql.mysql_user | Adds or removes a user from a MySQL database | | ansible.mysql.mysql_query | Run MySQL queries | | ansible.mysql.mysql_info | Gather information about MySQL servers | | ansible.mysql.mysql_variables | Manage MySQL global variables | | ansible.mysql.mysql_replication | Manage MySQL replication | | ansible.mysql.mysql_role | Adds, removes, or updates a MySQL role |

See also: The Bullhorn #227: Ansible Community Newsletter Highlights (May 2026)

FAQ

Will community.mysql stop working immediately?

No. Existing installations of community.mysql will continue to work. However, no new features or non-critical fixes will be released.

Are there breaking changes in ansible.mysql 5.0.0?

As a major version release, there may be breaking changes. Review the changelog before upgrading. The most significant change is the namespace itself (community.mysqlansible.mysql).

Can I use both collections simultaneously?

Technically yes, but it's not recommended. Having both installed may cause confusion about which modules are being used.

Does this affect MariaDB?

The ansible.mysql modules generally work with MariaDB as well, since MariaDB maintains MySQL protocol compatibility.

Conclusion

The transition from community.mysql to ansible.mysql is straightforward — primarily a namespace change. Migrate now while both collections are available to ensure a smooth transition. The ansible.mysql collection will receive all future development, features, and fixes.

Related Articles

Ansible Database Automation: PostgreSQL, MySQL, MongoDB, RedisAnsible PostgreSQL: Complete GuideAnsible Collections: Install, Use, Create Complete Guide

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home