OpenShift Container Platform (OCP) is a platform for developing and running containerized applications. It is designed to allow applications and the data centers that support them to expand from just a few machines and applications to thousands of machines that serve millions of clients.
OpenShift Container Platform version 4.14, you can install a cluster on your VMware vSphere instance by using installer-provisioned infrastructure.
Main Advantages of deploying OCP Cluster using Ansible Automation Controller/Ansible Tower – Using Ansible playbooks, automatically we can deploy multiple ocp clusters based on the requirement.
Prerequisites: –
You can check the OpenShift Cluster vSphere and network prerequisites in the Office OpenShift Portal –
Deployment Flow Diagram: –

You can also check my previous posts –
Deploying standalone Ansible automation controller – https://kdinesh.in/redhatansiblecontroller/
Deploying OCP 4.11 deploy using IPI without using Ansible – https://kdinesh.in/ocp/
Deploying OCP 4.11 on any platform using the UPI method – https://kdinesh.in/openshift/
Deployment Steps: –
Create a DNS record for the OCP Cluster.
Deploy an OCP deployment Linux VM on vSphere using Ansible automation Controller.
Deploy OCP Cluster
Creating a DNS record for the OCP Cluster: –
Create a DNS record for API VIP and Ingress VIP. (IN DHCP Range Reserve static IPS and use Reserved IPs from DHCP pool)
A complete DNS record takes the form: <component>.<cluster_name>.<base_domain
Example: – API VIP – api.ocp4.dineshk.in. Ingress VIP – *.apps.ocp4.dineshk.in.


After creating DNS records, Verify DNS.
Deploy an OCP deployment Linux VM on vSphere using Ansible automation Controller: –
In Gitlab, create a new project/use an existing project. Upload Playbooks.
You can download Playbooks using the following link – https://github.com/Dineshk1205/ocpansible

In the Ansible automation controller/Ansible tower, create a project. In the project, add GitLab as a source (Copy the project link from Gitlab and paste it into the Source Control URL). In the case of your GitLab project, create credentials and select credentials ).


After creating the project, check whether it’s successful or failed.
In Credentials, Create a VMware vCenter Credentials. (URL, username and password)

In Inventory, create a new Inventory and add the source as a vSphere.

Next, create a Template for deploying the OCP Deployment machine (Note: – You use a single deployment machine for deploying multiple clusters)
Select the Project above-created project and select vm. yaml playbook from the drop-down list (In the above steps, while creating the project, selected GitLab project repo, and automatically, it fetches info and shows available playbooks). Using vm. yaml ansible playbook, you can deploy vm’s on vSphere, not only specific to ocp deploy vm deployment.

In the template, Select Survey Option and add Variables. (The user will get a prompt window for selecting the VM deployment) (Note: – You may also predefine deployment variables in the playbook; however, if you are using the survey option, the user will get a prompt so that the user will give inputs based on the user inputs vm will be provided, So you can reuse the same playbook without changing in the playbook code)

Add the following variables to the survey.
vm_hostname (Question – VM_HOSTNAME, Ansible variable name – vm_hostname, Answer type – text. Save.
Similarly, add the following variables to the survey; based on the variable question, select the answer type (in some cases, you may select multiple options with single selects – ex: template, add existing vSphere templates so the user will get a drop-down list)
datacenter_name, folder, cluster_name, datastore, template, network, vm_ip, netmask, gateway, vm_hostname, dns1, dns2, vm_disk_size, memory_mb, vcpus.
After adding survey questions, enable Survey.
In Templates, select Template and click on the rocket icon. (Before launching Rocket, make sure that in the template vSphere credentials are chosen in the credentials option)

Will get Prompt, Specify VM deployment paraments. (make sure that the required OS template is available in the vCenter) (Note: – Recommended to use Cento/Redhat template)


Specify/select required VM deployment parameters. Click on next.

Review Details and check on the launch button.
VM deployment Job deployment started.

You can check in vSphere.VM deployment started.

VM deployment Job completed successfully.

You can see the screenshot below successfully VM created in vSphere.

Next, sync Ansible inventory and start deployment of OCP cluster using ocpdeployment vm.
Go to Inventory> Source>select source > Specify host filter as ocpdeployment(VM name, only particular name vm will be added to host)>click on sync.

Newly created VM added to hosts.

Deploying the OCP Cluster: –
Create a new ocp deployment template. In credentials, add machine credentials (Previously step deployed OS template username and password), and Select machine credentials. Select Inventory, project and select ocp4.15. yaml playbook from the drop-down list. Save.

Click the Pencil button to edit the template.

For VM deployment, we added a survey question and similarly add a survey question to ocp deployment.
Add the following variables as a survey question: –
vcenterurl, ocp_version, domian_name, ocp_computenode_name, ocp_computenode_replicas, ocp_compute_vcpus, ocp_compute_corepersocket, ocp_compute_memory_mb, ocp_compute_osdisksize, ocp_controleplanenode_name, ocp_controlplane_replicas, ocp_controlerplanenode_vcpus, ocp_controlplane_corepersocket, ocp_controleplanenode_memeory_mb, ocp_controlnode_osdisksize, ocp_clustername, ocp_clusternetwork, ocp_machinenetwork, ocp_networktype, ocp_servicenetwork, vcenter_username, vcenter_userpassword, vcenter_datacenter_name, vcenter_datstore_name, vcenter_network_name, vcenter_cluster_name, vcenter_foldername, ocp_api_vip, ocp_ingress_vip, ocp_pullsecret, ssh_key.
EX: – how to create a survey question

You can see the below screenshot. For ocp_computenode_name variables, the answer type is selected as a multiple choice (single select) option and a Specified Multiple option as worker and edge. Because the compute node name must be a worker or edge name. Cluster deployment will fail if you’re using any other name. Suppose if your select answer type text instead of multiple choice, Cluster deployment user may not be aware, he may choose a different name so that deployment will fail) Depending on the variable, choose the answer type.

Once all the required survey questions have been answered. Enable Survey and save. Click the Rocket button to launch the template.



Enter/Select the required inputs from the drop-down list. Click on Next.
Note: – You also configure additional/optional vSphere configure in install-configure.yaml file. Check reheat portal and update the ansible playbook according to your requirements.
Review Details. Click on the Launch button.

OCP deployment Job started.


You can check recent tasks on vCenter OCP cluster deployment started.

Bootstrap VM and master nodes deployed on vSphere. Once Master nodes are up, the Bootstrap VM will be terminated automatically. (Cluster deployment may take 30 minutes to 1hour, based on the environment)

You can log in to the ocpdeployment VM and check the master node status.
export KUBECONFIG=/root/ocp/auth/kubeconfig
oc get nodes or kubectl get nodes

Master nodes are ready so that the bootstrap VM will be terminated automatically.

Wait a few more minutes. Check Worker nodes are also deployed (3 masters and one worker node deployed successfully. Note: – Minimum three controllers mandatory on OCP Cluster deployment, Worker nodes based on your requirements you can deploy)

You can also check OpenShift GUI.
In ocpdeployment vm run command – kubectl get routes -n openshift-console (you will get URL)

GUI Default username – kubeadmin
Password – You can find in the OpenShift installation directory – auth – kubeadmin-password (cat /root/ocp/auth/kubeadmin-password)

You check the ansible job status. The ocp deployment job was completed successfully.


