From 91b703b0f0534badd1e8d5e81ef110d3583caf90 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 30 Apr 2019 19:43:07 +0530 Subject: [PATCH] [2.8] VMware: Handle VMs with no configurations Sometime VMs does not return any configurations which leads to failing the inventory plugin. Signed-off-by: Abhijeet Kasurde (cherry picked from commit 7505550500b6cf6eb89c973985d8141480c533ff) --- .../fragments/55929-vmware_vm_inventory-skip_orphan_vm.yml | 2 ++ lib/ansible/plugins/inventory/vmware_vm_inventory.py | 4 ++++ 2 files changed, 6 insertions(+) create mode 100644 changelogs/fragments/55929-vmware_vm_inventory-skip_orphan_vm.yml diff --git a/changelogs/fragments/55929-vmware_vm_inventory-skip_orphan_vm.yml b/changelogs/fragments/55929-vmware_vm_inventory-skip_orphan_vm.yml new file mode 100644 index 00000000000..bb7ce15693e --- /dev/null +++ b/changelogs/fragments/55929-vmware_vm_inventory-skip_orphan_vm.yml @@ -0,0 +1,2 @@ +minor_changes: +- Skip orphan VMs from inventory while running vmware_vm_inventory as VMs does not return any facts (https://github.com/ansible/ansible/pull/55929). diff --git a/lib/ansible/plugins/inventory/vmware_vm_inventory.py b/lib/ansible/plugins/inventory/vmware_vm_inventory.py index 165919b8538..a326cb8c4de 100644 --- a/lib/ansible/plugins/inventory/vmware_vm_inventory.py +++ b/lib/ansible/plugins/inventory/vmware_vm_inventory.py @@ -411,6 +411,10 @@ class InventoryModule(BaseInventoryPlugin, Cacheable): # VMware does not provide a way to uniquely identify VM by its name # i.e. there can be two virtual machines with same name # Appending "_" and VMware UUID to make it unique + if not vm_obj.obj.config: + # Sometime orphaned VMs return no configurations + continue + current_host = vm_obj_property.val + "_" + vm_obj.obj.config.uuid if current_host not in hostvars: