Skip to content

MySQL Module Playbook


This playbook provides direct access to an Ansible Module. The following Modules are supported by this playbook:

For each of the above modules, variable module_database must be defined. This variable is a dictionary of the options as are used by the module. The documentation for each module can be found by click on the module name above.

Playbook AWX / Ansible Automation Platform Template Import

This playbook includes the AWX feature where it imports the playbook as job templates in to AWX / Ansible Automation Platform. The following job templates that will be created:

  • Database/MySQL/Database/Create Create a Database

  • Database/MySQL/Database/Delete Delete a Database

  • Database/MySQL/Database/Dump Dump a database to a .sql file

  • Database/MySQL/Database/Import Import a database from a .sql file

On import to AWX / Ansible Automation Platform a credential type will also be created, playbook/mysql/login that can be used to supply the required secrets to log in to the database.

Module definitions

Each module definition is detailed below under the tab matching the module name. This directly shows what is or is not supported.

community-mysql-mysql_db.yaml
---
#
# No Fuss Computing
# https://gitlab.com/nofusscomputing/projects/ansible/ansible_playbooks
#
# image: nofusscomputing/ansible-ee > 0.11.0rc0

- name: Connection Validation - Assumed Socket
  ansible.builtin.assert:
    that:
      - module_database.host.socket is defined
    msg: "If no host DNS or IP Address is specified, you must supply the socket to use for the connection"
  when: module_database.host.name is not defined


- name: Variable Validation - Dump Database
  ansible.builtin.assert:
    that:
      - module_database.target is defined
    msg: "to dump a database, you must specify the path to save the dump"
  when: module_database.state == 'dump'


- name: Variable Validation - Import Database
  ansible.builtin.assert:
    that:
      - module_database.target is defined
    msg: "to Import a database, you must specify the path to the dump (.sql) file"
  when: module_database.state == 'import'


- name: Install MariaDB Dependencies
  ansible.builtin.apt:
    name: "{{ item }}"
    state: present
    install_recommends: false
  become: true
  loop: "{{ apps }}"
  vars:
    apps:
      - mariadb-client


- name: Install MariaDB required PIP Modules
  ansible.builtin.pip:
    name: "{{ item }}"
    state: present
  become: true
  loop: "{{ modules }}"
  vars:
    modules:
      - PyMySQL


- name: "{{ task_name_module | default('MariaDB Database Action') }}"
  community.mysql.mysql_db:
    login_host: "{{ module_database.host.name | default(omit)}}"
    login_user: "{{ nfc_pb_mariadb_username }}"
    login_password: "{{ nfc_pb_mariadb_password }}"
    login_port: "{{ module_database.host.port | default(omit) }}"
    login_unix_socket: "{{ module_database.host.socket | default(omit) }}"

    name: "{{ module_database.name }}"
    state: "{{ module_database.state }}"
    target: "{{ module_database.target | default(omit) }}"

  become: "{{ module_database.become | default(omit) }}"
  delegate_to: "{{ module_database.delegate_to | default(omit) }}"
  no_log: "{{ module_database.no_log | default(false) | bool }}"

About:

This page forms part of our Project Ansible Playbooks.

Page Metadata
Version: ToDo: place files short git commit here
Date Created: 2024-01-14
Date Edited: 2024-01-14

Contribution:

Would You like to contribute to our Ansible Playbooks project? You can assist in the following ways:

 

ToDo: Add the page list of contributors