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.
Are you trying to get a real-time inventory or are you scheduling an inventory update in ansible tower?
Walter
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!
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