vmware_vm_inventory and workflow templates

70 views
Skip to first unread message

Christopher Bachmeyer

unread,
Oct 4, 2022, 10:07:10 AM10/4/22
to Ansible Project
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.

---
# plugin: community.vmware.vmware_vm_inventory
plugin: vmware_vm_inventory
validate_certs: False
with_tags: False
groups:
  vmware: True
properties:
- 'name'
- 'config.name'
- 'guest.ipAddress'
hostnames:
- 'config.name'
filters:
- config.name == "at-test-vmt03t"

The first job Template runs without error, inside and outside of the workflow Template.  The InventorySource is picking up the host group "vmware" and the host "at-test-vmt03t", placing these objects appropriately.  However, I need to manually sync the Inventory for these objects to be picked up.  

The second job template cannot find the host group, "hosts: <host_group>" to execute the second job Template against. I also tried a variable given in the Survey for the ip "hosts: "{{ private_ip }}".  I also have tried using the set_stats module but I found this doesn't work either.  What am I missing here?

Thanks!

Rowe, Walter P. (Fed)

unread,
Oct 4, 2022, 10:33:25 AM10/4/22
to ansible...@googlegroups.com
Are you trying to get a real-time inventory or are you scheduling an inventory update in ansible tower?

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/57aeda52-15a3-46d3-93fa-a5b7c8a7e024n%40googlegroups.com.

Christopher Bachmeyer

unread,
Oct 4, 2022, 12:19:15 PM10/4/22
to Ansible Project
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!

Rowe, Walter P. (Fed)

unread,
Oct 4, 2022, 1:25:12 PM10/4/22
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Reply all
Reply to author
Forward
0 new messages