ansible-collections/community.mysql

mysql_upgrade

cwchristerw opened this issue · 4 comments

SUMMARY

I want to able to do mysql_upgrade with Ansible.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

mysql_upgrade

ADDITIONAL INFORMATION

It would make it possible to do mysql_upgrade without using shell module.

- name: "MySQL Upgrade"
  community.mysql.mysql_upgrade:
    host: "fd80:deaf:1::225"
    user: "root"
    password: "C7MEHzrdA7imJw3w"
    force: false

Hi @cwchristerw, thanks for the idea of a new module.

That said, maintaining a new module is a lot of work. I'm not sure this would add a significant value.

For reference, I have this playbook that do a mysql_upgrade:

# Playbook variables:
# - force (bool - default false)

- name: Run mysql_upgrade on a MySQL server
  hosts: single_instance
  gather_facts: false
  tasks:

    - name: Skip replicas
      ansible.builtin.meta: end_host
      when:
        (db_engine == 'mariadb' and mariadb_role == 'replica')
        or (db_engine == 'mysql' and mysql_role == 'replica')

    - name: Run mysql_upgrade
      become: true
      become_user:
        "{{ 'mysql' if db_engine == 'mariadb' else 'root' }}"
      ansible.builtin.command:
        cmd: "mysql_upgrade {{ '--force' if force | default(false) }}"
      register: upgrade_results
      changed_when: upgrade_results.stdout is not search('is already upgraded')

    - name: Display results
      ansible.builtin.debug:
        msg: "{{ upgrade_results.stdout_lines }}"
      when: upgrade_results.stdout_lines is defined

A module will remove the need to display the returned values with a debug task.
Do you see another advantage?

@cwchristerw hello, thanks for opening the issue.
I agree with @laurent-indermuehle : if the module is just a wrapper around shell commands (w/o making things much more convenient for users), i would suggest using existing solutions like the shell/command modules in this particular case.