A while ago, I published a post on automating Oracle Compute Service Cloud instances using Python and Ansible. Now that the Bare Metal Cloud Service is available, you can create a compute instance as well as other resources such DB instance on BMCS. In this post, I, again, use Python and Ansible to demonstrate automation of provisioning a compute instance on BMCS.
The use case implemented in this demonstration is described in a tutorial document: Oracle Bare Metal Cloud Services MEAN Stack Hands on Lab. If you are new to BMCS, this is a good tutorial to get started. This use case goes through the following main steps to eventually create a compute instance that runs Bitnami MEAN Stack.
The Python scripts included in this post generally follow the same steps. We use the BMCS Python SDK to perform step 1,2,3 and 5. Step 4 requires execution on the VM and for that, Ansible is used to run a shell script remotely from your local machine.
Here is a summary of my development environment:
Installed in parallel to the OS default Python 2.7.5. Version 2.7.13 is required by BMCS Python SDK.
Installed via yum. So it is on top of the default OS Python 2.7.5.
Configured Python interpreter in LiClipse to point to version 2.7.13.
A GSE BMCS instance was used to test the scripts.
Here is a list of artifacts required to execute the scripts.
Follow this Python SDK document to install the SDK on Python 2.7.13.
They are required for SDK API authentication. Check out Required Keys and OCIDs for information on how to obtain the OCIDs and key pair. You need to upload the public key to BMCS according to the same document. The included key pair can be used as well if you don't want to create your own.
BMCS resources are organized into compartments. In the GSE demo BMCS environment, users must create their resources in the assigned compartments. For example, user demo.user05 must create resources in Compartment 05. You can follow the image below to find the OCID for your compartment.
This key pair is required for SSH access to the compute instance once created. Follow the tutorial doc to create the key pair.
You can use the included bmcs_info.py script to retrieve the required information. But first, please update the BMCS Python SDK config file at workspace/bmcsproject/bmcs/config with your own tenant OCID, user OCID and path to the private API signing key file. Run bmcs_info.py and choose your preferred resources.
Update the included config file with the above information. A few more clarification on the properties:
key_file: the private API signing key file
pass_phrase: the password for the private key specified above. Out of the box, it contains the pass phrase for the contained API signing private key.
instance.ssh_authorized_keys: the content of SSH public key file
storage.size_in_mbs: use a number that is a power of 2
You can also change the display names and labels according to your preference.
Update the property private_key_file to point to your SSH private key file.
Use LiClipse to open the workspace and the bmcsproject. Three Python modules are included in the project:
bmcs_info.py: for retrieving information about the environment and instances
bmcs_create.py: for creating resources described in the tutorial document.
bmcs_delete.py: for removing all resources created by bmcs_create.py script
To run any of these scripts, have it open in LiClipse, right click to bring up the popup menu and select Run as --> Python Run.
If the execution is successful, two files will be created in directory ansible/playbooks/:
hosts: contains the public IP address of your newly created compute instance.
bmcs-config.sh: a shell script that mounts the block storage volume to a directory and downloads BitNami MEAN Stack.
In a Linux terminal, go to workspace/bmcsproject/ansible/playbooks/ and execute ./run-ansible.sh. Check out the playbook.yam to get more information on the tasks Ansible performs.
If all executions are successful, go to http://your-public-ip-address:8080 and you should see the home page of BitNami MEAN Stack.