Creating a Dynamic Inventory for OpenShift Virtual Machines
Lab Overview
Dynamic inventories allow Ansible Automation Platform (AAP) to automatically fetch and update the inventory of systems from external sources, eliminating the need for manual inventory management.
In this lab, we will configure a dynamic inventory to pull data from OpenShift
Virtualization. This will enable AAP to manage OpenShift VMs residing in the
vms-app-day2
namespace of an OCP cluster.
Add a Source to the Inventory
-
After creating the inventory, switch to the Sources tab.
-
Select the Create source button.
-
In the Create Source form:
-
Provide a name:
OpenShift Virtual Machines Source
. -
Select
OpenShift Virtualization
as the Source type. -
Choose
Default Execution Environment
as the execution environment. -
Add the
OpenShift Credential
(Bearer Token was pre-created) -
Select
Update on Launch
checkbox within Options. -
Set
Cache timeout
to0
seconds
-
-
Click the Create source button to save the configuration.
Test Connectivity of the Virtual Machines
In this lab, there will be three virtual machines running within your OpenShift environment.
Ensure that you can ping those VMs within the AAP dashboard https://aap-aap.apps.cluster-guid.dynamic.redhatworkshops.io as follows:
-
Login to the AAP Dashboard using the credentials above.
-
Navigate to Automation Execution → Infrastructure → Inventories
-
Select the
OpenShift Virtual Machines
Inventory -
Within the Details page of the
OpenShift Virtual Machines
Inventory, select the Hosts tab.
-
-
Select the 3 VMs and click the Run command button
-
Within the Run command Details, select the
ping
module and click Next. -
Within the Run command Execution Environment, Select the Day2 EE execution environment and click Next.
-
Within the Run command Credential, select the pre-created Workshop Credential and click Next.
-
Within the Run command Review, select Finish.
-
-
Verify Results: You should see a list of VMs along with their statuses similar to:
vms-aap-day2-rhel9-vm1 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": false, "ping": "pong" } vms-aap-day2-rhel9-vm2 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": false, "ping": "pong" } vms-aap-day2-rhel9-vm3 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": false, "ping": "pong" }
You may also confirm the VMs are running using the OpenShift UI dashboard https://console-openshift-console.apps.cluster-guid.guid.sandbox.opentlc.com:
Virtualization → VirtualMachines within the vms-aap-day2
project.