Overview

Ansible and Oracle allow you to automate a lot of things around the OCI. In this module we will address the automation of:

Compute Node Creation

MySQL Creation

MySQL Replication Setup

In later modules, we will make it even better with the introduction of roles. So let's get going. P.S. A disclaimer is in order here….I will not share my compartment or SSH keys…..obviously :D

Compute Node

Ansible has variable of modules for the compute node or for anything in general, but the following playbook automate the creation of a compute node.

Of course you need to create a VCN prior that with the correct name:

Create a compute node

Actually that command, created the server on which that page is currently running :D

Playbook

The playbook you can see below:

setup_computenode.yml

So the playbook, won't create a compute node which already exist and it will also verify that the server has been created :)

MySQL Setup

Now, since OCI stands for Oracle Cloud Interface, well…they have Oracle Linux and AS SUCH, by default it is MySQL 8, so…my first task is to DELETE the MySQL 8 :D in my playbook. Then I install the new packages and so on so far…. :)

MySQL Deployment

For the people who are wondering what the: “oci_inventory.py” is. It is a file by Oracle, which allows you to create dynamic inventory based on your OCI, so I don't have to keep a track of if a server still exist or I killed it….brutally I might add.

Playbook

Again, the playbook you can see below:

setup_mysql.yml

Now, of course, I will change the configuration with a template and so on, but that is for a later module.

MySQL Replication & Refresh

Now, in order to configure replication and refresh. We need to implement the snapshot of the block device. But wait…we didn't configure a block device yet, so let's get that going.

Block device

To configure a block device you can use the following command:

Block device config

The playbook itself, you can see below:

setup_storage_computenode.yml

That playbook, will create a block device, attach it and also attach it on the host using the following playbook:

execute_shell_commands

With all that, we can finally configure the refresh (resnap) and configure the replication:

Resnap the primary block device

setup_resnap

That playbook will use our final playbook: “setup_replication”, which you can see below:

Setup replication

Setup replication

With this, we were able to setup replication using OCI and ansible. The resnap can be done as many time as needed. It will always clone the primary's block device and attach it on replica, then it will re-establish replication.

There is one more playbook which we need to add.

detach_iscsi

That playbook will stop the MySQL and detach the iSCSI from the compute node, so we can safely, remove it from the OCI as well.

MySQL Clusterset Automation

This ansible project consists of 3 roles:

MySQL Instance

MySQL InnoDB Cluster

MySQL Router

That will create architecture with 1 InnoDB Clusterset and a replicaset attached to it. The full code, you can see here:

https://github.com/JulienAndonov/MySQL_Cluster_Ansible