VMwarevCenter Server tags are labels that can be applied to objectslike the system's environment and usage, therefore it is a very usefulmethod of asset management - also making tags a perfect fit in theAnsible world to organize systems in an Ansible inventory. Red Hatcustomers have regularly requested the ability to use vCenter Tags inRed Hat Ansible Tower. This is now possible with an Ansible Towerinventory source that supports tags and provides thevmware_vm_inventoryplugin.
Ansible Automation Platform 1.2 brings completely native Ansibleinventory plugin support to Ansible Tower 3.8. In previous versions,there were specific inventory plugin configurations based on the oldinventory scripts where a specific set of parameters surfaced in AnsibleTower's user interface. For example: cloud region and a specific subsetof variables you could pass to those inventory scripts surfaced asvariables you could pass to the inventory source, which means that newconfiguration parameters that come with Ansible inventory plugins arenot supported in order to maintain compatibility with the old inventoryscripts.
The move to support native inventory plugins allows Red Hat AnsibleAutomation Platform customers to use all the configuration parametersavailable through the plugin, as well as supporting any future newplugin features automatically.
So as an example, the screenshot below shows the source configurationpanel difference between an older version of Ansible Tower (3.7 in thiscase) and the new source configuration in Ansible Tower 3.8. Thisspecific example is for an Amazon EC2 source in Ansible Tower 3.8:
As you can see, the "Instance Filters" and "Regions" configurationoptions are no longer a part of the user interface in Ansible Tower 3.8,but the configuration can now be done in the "Source Variables" sectionof the inventory source definition. This Ansible Tower instance wasactually upgraded from 3.7 to 3.8, and during the upgrade, the platforminstaller takes old inventory sources and converts them to a compatibleinventory plugin configuration - therefore there will be a lot ofentries in the section to maintain the same outcome for upgradedsources - groups created by default for example - as the old inventoryscripts.
So thevmware_vm_inventoryplugin supports tags using a configuration parameter -with_tags -which defaults to false - so we will need to set that to true in oursource definition, but as stated in the documentation linked above,using this parameter requires the vSphere Automation SDK library tobe installed on the controller machine - in our case, the Ansible Towernodes. The documentation also links to thisURL forthe installation steps.
First step is to make sure that our Ansible Tower nodes have therequired library to use this feature. As we can use an inventory sourcewith a custom python virtual environment, we will create a new pythonvirtual environment under /opt/towervenvs called vmware-venv, and willbe installing the required libraries in that environment (you can readmore about Ansible Tower's virtual environments and how to use them in thedocumentation).
Make sure that the virtual environment and the required libraries areinstalled on all nodes in the Ansible Tower cluster, and that AnsibleTower is configured to look for virtual environments under the directorythey are defined in. This setting can be found underSettings > System > CUSTOM VIRTUAL ENVIRONMENT PATHS
In Ansible Tower, from the left hand panel under resources select"Credentials" and click the add icon and add a new credential. In thenew credential configuration panel, enter a name for your new credentialand choose "VMware vCenter" as the credential type and fill in therequired information - here is what the credential definition lookslike:
Now it's time to create the inventory. In Ansible Tower, from the lefthand panel under resources, select "Inventories" and click the add iconand add a new inventory. Give the inventory a name and select anorganization for the inventory - we'll call ours "VMwareInventory", and assign it to Red Hat Organization.
Click "Save" and the sources tab is now enabled. Now go to the sourcestab, click the add icon to add a new source - Give it a name, and chooseVMware vCenter as the source, and choose the credential that we createdearlier (the credential may already be auto populated if it's the onlycredential of the type "VMware vCenter" defined), and make sure toselect the virtual environment that has the required library installedunder it.
Our new inventory source is now created and will appear under sourcesLet's now click on the sync icon to pull in our list of virtual machines(VMs). After the sync job completes, and the cloud icon next to thesource turns green, we can now go into the list of hosts and see all thehosts that are in vCenter, and if we click on any of the hosts we cansee the associated tags under the "tags" key. Awesome!
The previous configuration will pull in all the hosts in vCenter withtheir associated tags, and the guest attributes we defined based on whatis available in the inventory plugin's documentation. But we only wantto pull in VMs that have the tag "TestVM", and we want to create groupsbased on the tags associated with the VMs that are imported, their powerstate and their guest ID. So let's add some filters, as well as somekeyed groups definition. Go back to the inventory source we defined, andreplace the definition under source variables with the following:
The new native Ansible inventory plugin support may upgrade the level ofdifficulty, as you will have to know how to configure the inventoryplugin you want to use, but it gives users a lot of flexibility.
3a8082e126