In this blog posting we will be looking at BigAnimal cluster management via BigAnimal’s APIs with Ansible.
In case you would like to review details about BigAnimal, you can take a look at a previous blog posting: “Managing BigAnimal Clusters with BigAnimal APIs”, in which we reviewed and explained what is:
- DBaaS
- BigAnimal
- BigAnimal Cluster
We also discussed What BigAnimal is, its features and capabilities.
Ansible
Ansible is an open-source provisioning, and configuration management software written by Michael DeHaan and acquired by Red Hat in 2015.
Why use Ansible and BigAnimal?
A few reasons for utilizing Ansible together with BigAnimal are:
- Ansible is a tool for automating infrastructure - Infrastructure as Code
- Deploying and managing applications
- Yaml based, simple to learn, and organized within yaml files named “Playbooks”
- Easy to assimilate into DevOps pipelines
- Simplifies the process of provisioning resources in the Cloud
- Easy to learn
Prerequisites
- Ansible previously installed
- Previously configured BigAnimal credentials and token
- Completed ‘data.json’ for passing all the cluster configuration to the API
- Code that has been provided for this blog posting
Obtaining a Token
A BigAnimal token is created by executing the script ‘get-token.sh’ as shown below:
get-token.sh |
After following the instructions displayed on the console, a successful token assignment looks somewhat as below
{ |
From the message above, we can tell how long the token will last, which is listed in seconds under the “expires_in” setting.
Should there be a need to obtain more tokens the same process can be executed as many times as needed.
Creating a Cluster
Once you have all the prerequisites readily available, we can proceed to edit the “data.json” file with the desired cluster configuration:
{ |
The values to be configured should be:
- Cluster Name
- Password
- Postgresql Type
- Postgresql Version
- Provider
- Region
- Instance Type
- Volume Type
- Volume Properties
- High Availability
- Networking
- Confirmation of cluster creation
The next step is to edit the: “variables.yml” file and look for the section where you assign the token, which is on line 7. The “variables.yml” file content should look similar to this:
token: "<yourtoken>" biganimal_server: https://portal.biganimal.com/ # Match the name, provider pgType and pgVersion to desired filters list_endpoint: api/v1/clusters?name=DO-ansible&provider=azure&pgType=epas&pgVersion=14&sort=%2Bname provision_endpoint: api/v1/clusters status_endpoint: api/v1/clusters pgId: <your_biganimal_cluster_id> status_healthystate: Cluster in healthy state |
The values available for configuration within this file are:
- token
- biganimal_server - URL for the BigAnimal portal
- list_endpoint - suffix to be appended to the “biganimal_server” url
- provision_endpoint - suffix to be appended to the “biganimal_server” url
- status_endpoint - suffix to be appended to the “biganimal_server” url
- pgId - BigAnimal cluster Postgres Id
- status_healthystate - Text to display when a BigAnimal Cluster is in healthy state
The code to create a cluster is located inside the “provision.yml” file, it looks like this
#
Original work by: EnterpriseDB |
The code above:
- Assigns the token, headers, and url to variables
- Performs a POST request
- Displays the status from the request, and the response data.
A few items to note:
- The token must be assigned in the “variables.yml” file where the “token” variable is defined
- Basic error handling can be improved
- The status of the API call is displayed at the end of the code
The next step in the process is to execute the ansible playbook:
ansible-playbook provision.yml |
A successful cluster creation will provide a message that looks somewhat as below
PLAY
[localhost] *************************************************************** |
A key step is to note the value in the: “provision_results.json.pgId”, which is the BigAnimal Cluster pgId. This value must be copied into the “variables.yml” file under the “pgId” variable.
Listing Clusters
Listing clusters is accomplished by assigning the token in the “list.yml” file along with values configured in the “variables.yml” file for:
- token
- biganimal_server
- list_endpoint
- provision_endpoint
- Status_endpoint
- pgId
- status_healthystate
The code to list a cluster is located inside the “list.yml” file, it looks like this
#
Original work by: EnterpriseDB |
Similar to the previous code file, the code above:
- Assigns the token, headers, url, and filter to variables
- Performs a GET request
- Displays the status from the request, and the response data.
Notice the items below in the code above:
- The token must be assigned where the “token” variable is defined
- The “list_endpoint” variable in the “variables.yml” might need some adjusting to fit the parameters of the clusters to list. It is not needed to include: provider, pgType, pgVersion, nor the sort parameters
The execution command to list the clusters available to the current credentials is:
ansible-playbook list.yml |
Listing clusters results:
PLAY
[localhost] *************************************************************** |
Deleting Clusters
To delete the BigAnimal clusters, we need to update the token and the pgId in the “variables.yml” code file.
The code to delete a cluster is located inside the “destroy.yml” file, it looks like this
#
Original work by: EnterpriseDB |
In the delete code file, the code above:
- Assigns the token, headers, pgId, url, and filter to variables
- Performs a DELETE request
- Displays the status from the request, and the response data.
Notice the items below in the code above:
- As the other code files, the token must be assigned where the “token” variable is defined in the “variables.yml” file
- The BigAnimal Cluster Id must also be assigned
The execution command to delete a cluster is:
ansible-playbook destroy.yml |
A successful cluster deletion will provide a message that looks somewhat as below
PLAY
[localhost] *************************************************************** |
Inspecting how it all works together
Now that we know what each code file accomplishes, we can stop and take a look at the underlying technologies and how all the pieces fall into place.
The top block provides the BigAnimal API services to the bottom block that assembles the json and token into a message that is returned the the API call itself. It is very easy to overlook every step that occurs and while not all inclusive the diagram above does provide a deeper view at what happens behind the scenes.
Conclusion
In this blog we used Ansible and learned how to:
- Obtain a BigAnimal token
- Create a BigAnimal cluster
- List BigAnimal clusters
- Delete a BigAnimal cluster
Try it out for yourself in our BigAnimal test drive environment. See you in the next blog post!
No comments:
Post a Comment