Automate Compute Service Management on BMCS with Python and Ansible


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.

Use Case

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.

  1. 1. Create a Virtual Cloud Network (VCN)
  2. 2. Create a Virtual Machine (VM) instance
  3. 3. Create a Block Volume Storage and attach it to the VM
  4. 4. Download and install Bitnami MEAN Stack (performed on the VM)
  5. 5. Configure security list of the VCN to expose ports

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:

Oracle Linux 7.3

Python 2.7.13 with PIP

Installed in parallel to the OS default Python 2.7.5. Version 2.7.13 is required by BMCS Python SDK.

Ansible 2.3.1

Installed via yum. So it is on top of the default OS Python 2.7.5.

LiClipse 4.0.0

Configured Python interpreter in LiClipse to point to version 2.7.13.

Oracle GSE Demo BMCS

A GSE BMCS instance was used to test the scripts.



Here is a list of artifacts required to execute the scripts.

Install BMCS Python SDK

Follow this Python SDK document to install the SDK on Python 2.7.13.

BMCS access credentials: Username, Password and Tenant ID
BMCS Tenant OCID (Oracle Cloud ID), User OCID, Signing Key Pair and its Finger Print

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 Compartment OCID

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.


SSH Key Pair

This key pair is required for SSH access to the compute instance once created. Follow the tutorial doc to create the key pair.

Availability Domain Name, Image OCID and Shape OCID

You can use the included 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 and choose your preferred resources.


Update Config Files

BMCS Python SDK Config File: workspace/bmcsproject/bmcs/config

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.


Ansible Config File: workspace/bmcsproject/ansible/playbooks/ansible.cfg

Update the property private_key_file to point to your SSH private key file.

Running the Python Script

Use LiClipse to open the workspace and the bmcsproject. Three Python modules are included in the project: for retrieving information about the environment and instances for creating resources described in the tutorial document. for removing all resources created by 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. a shell script that mounts the block storage volume to a directory and downloads BitNami MEAN Stack.

Running Ansible

In a Linux terminal, go to workspace/bmcsproject/ansible/playbooks/ and execute ./ 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.


Add Your Comment