Installing MariaDB

As we have been using the IUS repository for other packages in our playbook, it would make sense to install the latest version of MariaDB from there. However, there is a conflict we need to resolve first.

As part of the base Vagrant box installation, Postfix, the mail server, is installed. Postfix requires the mariadb-libs package as a dependency, but having this package installed is going to cause a conflict with the later version of the package we want to install. The solution to this problem is to remove the mariadb-libs package and, then install the packages we need, along with Postfix, which is removed when we uninstall mariadb-libs.

The first task in the role, which we need to add to roles/mariadb/tasks/mail.yml, looks like the following: 

- name: remove the packages so that they can be replaced
yum:
name: "{{ item }}"
state: "absent"
with_items: "{{ mariadb_packages_remove }}"

As you may have already suspected, mariadb_packages_remove is defined in the roles/mariadb/defaults/main.yml file:

mariadb_packages_remove:
- "mariadb-libs.x86_64"

As you can see, we are using the full package name. We need to do this because if we simply used mariadb-libs, then the newly installed package would be removed during each playbook run. This is bad as this task would also uninstall all of the MariaDB packages we are going to be installing next, which, if we have a live database running, would be a disaster!

To install the later version of MariaDB, we need to add the following task:

- name: install the mariadb packages
yum:
name: "{{ item }}"
state: "installed"
with_items: "{{ mariadb_packages }}"

The mariadb_packages variable, which again can be found in the defaults folder, looks like the following:

mariadb_packages:
- "mariadb101u"
- "mariadb101u-server"
- "mariadb101u-config"
- "mariadb101u-common"
- "mariadb101u-libs"
- "MySQL-python"
- "postfix"

We are installing the packages for MariaDB, along with Postfix, which was removed during the last task. We are also installing the MySQL-python package, which will allow Ansible to interact with our MariaDB installation.

By default, MariaDB does not start as part of the installation process. Typically, we would use a handler to start the service as part of the playbook run, and, as we have learned from the previous sections, the handlers run at the very end of the playbook execution. This would not be a problem if we didn't need to interact with the MariaDB service to configure it. To get around this, we need to add the following task to our role:

- name: start mariadb
service:
name: "mariadb"
state: "started"
enabled: "yes"

This makes sure that MariaDB is running, as well as configuring the service to start on boot.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.253.152