# vmware\_vm\_inventory and workflow templates

**URL:** <https://forum.ansible.com/t/vmware-vm-inventory-and-workflow-templates/37174>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [October 4, 2022, 2:07pm UTC](https://forum.ansible.com/t/vmware-vm-inventory-and-workflow-templates/37174 "2022-10-04T14:07:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bachmeyer](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Chris\_Bachmeyer](https://forum.ansible.com/u/Chris_Bachmeyer)\
**Post date:** [October 4, 2022, 2:07pm UTC](https://forum.ansible.com/t/vmware-vm-inventory-and-workflow-templates/37174/1 "2022-10-04T14:07:10Z")

</div>

Hi Ansible group,

I am working on constructing a workflow Template using Ansible Tower 3.8.3 with Ansible ver. 2.9.27. The workflow Template consists of just two job Templates, each one with code residing in separate repos. I created an Inventory in Ansible Tower with a Source “InventorySource - VMware deployments” that contains the vmware\_vm\_inventory plugin under Source Variables.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [October 4, 2022, 2:33pm UTC](https://forum.ansible.com/t/vmware-vm-inventory-and-workflow-templates/37174/2 "2022-10-04T14:33:05Z")

</div>

Are you trying to get a real-time inventory or are you scheduling an inventory update in ansible tower?

Walter

---

<div class="post-metadata">

**Author:** ![Chris\_Bachmeyer](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Chris\_Bachmeyer](https://forum.ansible.com/u/Chris_Bachmeyer)\
**Post date:** [October 4, 2022, 4:19pm UTC](https://forum.ansible.com/t/vmware-vm-inventory-and-workflow-templates/37174/3 "2022-10-04T16:19:15Z")

</div>

Hi Walter,

I am trying to get a real-time inventory based off of job Template 1 (jT1). I added a filter to the plug-in to filter for the config.name. I “think” ideally I’d like to filter based on a tag, i.e. those instance(s) with tag would be put into the specified Inventory. Job Template 2 (jT2) would then execute using the tagged inventory. That make sense?

The documentation for the vmware inventory filtering is quite poor so I am not sure, yet, on how to filter for tags.

In a separate directory I do have an ansible.cfg with the enable\_plugins parameter and the vmware\_vm\_inventory.yml. I can grab a list of the inventory by running …  
“$ ansible-inventory -i vmware\_vm\_inventory.yml --list”

The goal is to create vms from a template and hence new inventory then shuttle this inventory over to jT2 for any additional post-processing.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [October 4, 2022, 5:24pm UTC](https://forum.ansible.com/t/vmware-vm-inventory-and-workflow-templates/37174/4 "2022-10-04T17:24:50Z")

</div>

So … the vmware\_vm\_inventory … I sense from the documentation that this builds an inventory that is only valid for the context of the running playbook. You cannot pass that inventory downstream in a workflow to another playbook. You could create a list of hostnames as an artifact using set\_stats in JT1. In JT2 craft a simple first play that runs on hosts: localhost and builds an inventory group using addhost, and then reference that inventory group in “hosts: my\_group” in play number 2 in the JT2. use that same variable in the hosts argument.

**JT1:**

- name: create my\_hosts list artifact for downstream jobs templates  
set\_stats:  
data:  
my\_hosts: “{{ list of hostnames from vmware\_vm\_inventory plugin }}”

**JT2:**

- name: build dynamic inventory host group from upstream artifact my\_hosts list  
hosts: localhost  
tasks:

- name: add {{ item | lower }}  
add\_host:  
name: “{{ vm\_guest\_name | lower }}”  
group: my\_hosts\_group  
loop: “{{ my\_hosts }}”

- name: execute tasks against dynamic inventory group my\_hosts\_group  
hosts: my\_hosts\_group  
tasks:

- name: task1 for vm\_group inventory  
some\_module:

- name: taskN for vm\_group inventory

some\_module:

See if this gets you going …

Walter
