This is the second part in how you can setup Vmware inventory in AWX based on VM tags. Link to first part.
Create a file that ends with vmware.yml or vmware.yaml. For example invent. I called my file invent.vmware.yml
---
plugin: vmware_vm_inventory
strict: False
hostname: vc.homelab.domain.com
validate_certs: False
with_tags: True
hostnames:
- 'config.name'
compose:
ansible_host: 'guest.hostName'
keyed_groups:
- key: 'tags'
separator: ''
Make sure to set you hostname and check in your file in a Git repository.
Create a project, my is called Inventory an select Git as SCCM Type. Add you Git repository URL as SCM URL. Don´t forget to create SCM credentials if you haven’t done that already. Set /opt/my-envs/vm-tags as Ansible environment.

Next step is to create a custom credential type. I called my Vmware_Inventory

#Input configuration
fields:
- id: username
type: string
label: Username
- id: password
type: string
label: Password
secret: true
required:
- username
- password
#Injector configuration
env:
VMWARE_PASSWORD: '{{password}}'
VMWARE_USERNAME: '{{username}}'
Create a new credential with your new credential type. You will need a user with read permissions in your Vcenter server.

Go to Inventory and create a new Inventory and give a name and hit Save.

Click sources and create a new source. Give it a name and select Sourced from a project as a sources. Set /opt/my-ens/vm-tags/ as ansible environment. Search for and select for your credential with read permission in Vcenter.

Now you should be able to sync your new inventory.

After the sync has finished you should see your hosts and groups.

For example I have connection details as a group variable on my group win. All my windows server are in the group win. I needed you cand have second group like SQL servers and then add that group to win group to allow it to inherit all win group variables.
---
ansible_winrm_server_cert_validation: ignore
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_transport: kerberos

That’s it, hopefully this can be helpful to any one seeking information about AWX and Vmware tags as inventory groups.
Hello,
thank you for your doc, but i’m trying to follow step by step what you did but without success.
can give me step by step the configuration.
or put the file vmware.yml or vmware.yaml
I added the Custom virtual environment paths in system, but no new ansibe environment in sight in the organization.
can help me please.
LikeLike
how far have you come? Have you completed part 1 and can see your custom variable? vmawre.yml is the file at the top section called invent.vmware.yml in my example.
LikeLike
hello I am French, I found a solution based on your example. I do that:
docker exec -ti awx_task bash
source / var / lib / awx / venv / ansible / bin / activate
yum install gcc
yum install python36-devel
pip3 install –upgrade pip
pip3 install –upgrade azure-cli-core
pip3 install –upgrade wheel
pip3 install psutil
pip3 install ansible
pip3 install pyaml
pip3 install requests
pip3 install PyVmomi
pip3 install –upgrade pip setuptools
pip3 install –upgrade git + https: //github.com/vmware/vsphere-automation-sdk-python.git
deactivate
exit
then I connect to AWX in http and create an inventory with your variables:
—
plugin: vmware_vm_inventory
strict: False
hostname: vc.homelab.domain.com
validate_certs: False
with_tags: True
hostnames:
– ‘config.name’
compound:
ansible_host: ‘guest.hostName’
keyed_groups:
– key: ‘tags’
separator: ”
however would it be possible to help me in the selections of hosts to show, for example:
do not display templates
do not display turned off VMs
display VMs according to OS
display VMs according to tags
display VMs according to custum
please, thank you and again thank you for your doc, we must continue to propose topics.
what about you, where do you come from?
LikeLike
You can filter out templates and poweredoff VMs. Just add this row to vmware.yml.
filters:
– summary.runtime.powerState == “poweredOn”
You can find more examples here. https://docs.ansible.com/ansible/latest/scenario_guides/vmware_scenarios/vmware_inventory_filters.html
I am from Sweden, working for a Swedish company owned by the French company Saint-Gobain.
LikeLike
cool that the world is small, i know the saint-gobin company, i work for the ministry of defense and i need to set up a private cloud. the problem is that i don’t know the CICD part and have a hard time launching playbooks only on vms with a well-defined tag. I thank you for your help a +.
LikeLike