Installing MariaDB on Ubuntu 22.04 with Ansible

Introduction 

MariaDB is a relational database management system fork developed by the community and commercially supported under the GNU General Public License. It is intended to remain free and open-source software.

Ansible is a collection of software tools that let infrastructure be written in code. Software provisioning, configuration management, and application deployment are all included in the open-source suite.

Prerequisites

  • Up and running Ansible server.
  • Root access of target machine.
  • Internet connectivity with nodes.

We’ll show you how to use the Ansible automation tool to install the MariaDB Database server on a Ubuntu machine in this post.

Step 1: Creating MariaDB Playbook

We need to create a mariadb-playbook.ymlAnsible play is very import to to execute the task one by one.

To create a mariadb-playbook.yml

nano mariadb-playbook.yml

Paste the following code.

- name: Install MariaDB
  hosts: mariadbservers
  become: true
  
  tasks:

  - name: Update apt-get repo and cache
    apt: update_cache=yes force_apt_get=yes cache_valid_time=3600 

  - name: Install MariaDB
    apt:
      name: mariadb-server
      state: present
  
  - name: Start MariaDB
    service:
      name: mariadb
      state: started
      enabled: yes

Save and exit from the text editor, This playbook does the following:

  • Adds the MariaDB repository to the remote server.
  • Imports the MariaDB GPG key.
  • Installs MariaDB.
  • Starts the MariaDB service and enables it to start automatically on boot.

Note that this is just one example, and the specific details of your playbook will depend on your use case and the specific version of MariaDB you’re using

Step 2: Execute MariaDB Playbook

We are good to execute the mariadb-playbook.yml by following the given command.

ansible-playbook mariadb-playbook.yml

The above command start the installation of MariaDB database server on target machine.

Step 3: Testing MariaDB 

We need to execute the  sudo mysql  to take mysql shell access, Use the following steps for the same.

To Login MariaDB. 

sudo mysql

You should get output like this.

Conclusion

We have successfully installed MariaDB Database server on Ubuntu 22.04 LTS with ansible. If you still have any questions, please leave a comment below: 

Author

Installing MariaDB on Ubuntu 22.04 with Ansible

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top