How to install MariaDB using Ansible Playbook on Ubuntu

Sometimes we need to automate the installation of packages on multiple servers. In this section, we will create an Ansible Playbook to install a MariaDB server.

We believe, You have already installed Ansible if not you need to click on given link to install Ansible on ubuntu server If not go to this link to install Ansible first.

https://www.techbeginner.in/2019/12/how-to-install-ansible-on-ubuntu.html

Step 1: Configure Ansible

By default ansible host configuration file is /etc/ansible/hosts Here you need to add the MariaDB server details like this, Use the following step for the same, In my case i have 1 MariaDB database server.

  • Group Name  – Database
  • IP Address     – Your IP Address
  • Username      – example
  • Password       – XXXXXXXXXX

You need to add your server in ansible host file, Syntax is given below, You need to open the /etc/ansible/hosts file with nano or vim text editor.

sudo vim /etc/ansible/hosts

and add the web server entry like this.

[database]
localhost ansible_connection=ssh ansible_ssh_user=ubuntu ansible_ssh_pass=xxxxxxx

Change the credentials as per your environment, Save and exit from the vim text editor and verify the host machine connectivity with ansible by using the given command.

ansible all -m ping

You should get output like this.

Here our host configuration is completed and now we can go for next step to write play book.

Step 2: Creating MariaDB Ansible Playbook

You need to create a mariadb-playbook.yml and you change it according to your requirement.

sudo vim mariadb-playbook.yml

Paste the given code.

- hosts: database
  become: yes
  tasks:

      - name: Install MariaDB repository 10.3
        apt_repository: repo='deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu xenial main' state=present
    
      - name: Add repository key to the system
        apt_key: keyserver=hkp://keyserver.ubuntu.com:80 id=0xF1656F24C74CD1D8

      - name: update
        apt: update_cache=yes   
        ignore_errors: yes      

      - name: Install MariaDB Server 10.3
        apt: name=mariadb-server state=latest
        
      - name: Install MariaDB Client 10.3
        apt: name=mariadb-client state=latest

      - name: Restart MariaDB 10.3
        service: name=mysql state=restarted

Now we are ready to use the mariaDB’s PlayBook, To execute the PlayBook you need to use the given command.

ansible-playbook mariadb-playbook.yml

While execution of ansible playboook, You should get the status of each step taken by ansible,

Conclusion

We have successfully installed MariaDB using Ansible playbook on ubuntu 22.04 LTS, Kindly report in case you are facing defeculties with follwing details.

  • OS
  • Ansible version
  • Package name
  • Logs – Error / Warning / failed

    Get in touch with our new devops tools based website- https://www.devopstricks.in/

    How to install MariaDB using Ansible Playbook on Ubuntu

    One thought on “How to install MariaDB using Ansible Playbook on Ubuntu

    Leave a Reply

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

    Scroll to top