Cook in OCI with Ansible modules – part 2

Today part 2 of the Ansible code for OCI.  Last time, within the previous blog post (part 1),  I have created OCI infrastructure with simple VM on top, right? Now let’s execute playbook no. 2. This playbook will access the VM and will install webserver software. Successful execution means the index.html page will be accessible from the outside world. Here is a code you should analyze a little bit:


As you can see we will execute the code on the machine which we have had created in step 1. But how it is derived? As you can see we will use Ansible dynamic groups, which are derived from dynamic inventory. In our case host will be derived from freeform tags, which we have had created as a part of machine launch.

It is also important to look into shell scripts which encapsulate ansible-playbook utility execution.  As you can see it will get the list of OCI hosts dynamically (please check -i parameter):

ansible-playbook playbooks/install_webserver_on_oci_compute.yml -i /home/opc/oci-ansible-modules/inventory-script/ -u opc --private-key /home/opc/id_rsa -vvv

Ok, but let’s return to playbook itself. After including variables, our code will install the httpd package, then index.html will be uploaded from the template. Finally, our local VM firewall will be disabled and httpd service will be enabled. Pretty simple.

Let’s check it up in practice. So let’s execute STEP2 of the automation…


… and after 1-2 minutes we will see the result:


Ok. This is what we have planned to have. Short story, the dish has been cooked.


Martin, MasterChef 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s