From c97360d21f2ba003abc881b9b3d03ab0ef672508 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Sat, 7 Dec 2019 01:53:12 +0530 Subject: [PATCH] vmware: vmware_vm_inventory use port value when with_tags:True (#65568) If user specifies a port number in vmware_vm_inventory plugin configuration, then use that port to connect to vCenter rather than connecting to 443 which is default port. Fixes: #64096 --- changelogs/fragments/vmware_vm_inventory_port.yml | 2 ++ lib/ansible/plugins/inventory/vmware_vm_inventory.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/vmware_vm_inventory_port.yml diff --git a/changelogs/fragments/vmware_vm_inventory_port.yml b/changelogs/fragments/vmware_vm_inventory_port.yml new file mode 100644 index 00000000000..e18faac07c6 --- /dev/null +++ b/changelogs/fragments/vmware_vm_inventory_port.yml @@ -0,0 +1,2 @@ +bugfixes: +- vmware_vm_inventory inventory plugin, use the port value while connecting to vCenter (https://github.com/ansible/ansible/issues/64096). diff --git a/lib/ansible/plugins/inventory/vmware_vm_inventory.py b/lib/ansible/plugins/inventory/vmware_vm_inventory.py index bd8e4d2ad8f..816b6471c5d 100644 --- a/lib/ansible/plugins/inventory/vmware_vm_inventory.py +++ b/lib/ansible/plugins/inventory/vmware_vm_inventory.py @@ -163,12 +163,15 @@ class BaseVMwareInventory: # Disable warning shown at stdout requests.packages.urllib3.disable_warnings() - client = create_vsphere_client(server=self.hostname, + server = self.hostname + if self.port: + server += ":" + str(self.port) + client = create_vsphere_client(server=server, username=self.username, password=self.password, session=session) if client is None: - raise AnsibleError("Failed to login to %s using %s" % (self.hostname, self.username)) + raise AnsibleError("Failed to login to %s using %s" % (server, self.username)) return client def _login(self):