Repository: ansible-collections/community.vmware

Issue:
vm tools connection plugin incompatible with latest version of pyvmomi


##### SUMMARY
The vmware_tools connection plugin attempts to run the import statement `from pyVim.connect import Disconnect, SmartConnect, SmartConnectNoSSL` but `SmartConnectNoSSL` was removed from pyvmomi as of the 8.0 release, as detailed here - https://github.com/vmware/pyvmomi/releases/tag/v8.0.0.1

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
The connection plugin community.vwmare.vmware_tools

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes -->
```paste below
ansible [core 2.14.1]
  config file = /Users/michaelgaruccio/code/pmm-morpheus-migrations/ansible.cfg
  configured module search path = ['/Users/michaelgaruccio/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/michaelgaruccio/.local/share/virtualenvs/pmm-morpheus-migrations-nfisJWJS/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/michaelgaruccio/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/michaelgaruccio/.local/share/virtualenvs/pmm-morpheus-migrations-nfisJWJS/bin/ansible
  python version = 3.9.7 (default, Nov  5 2021, 16:21:26) [Clang 13.0.0 (clang-1300.0.29.3)] (/Users/michaelgaruccio/.local/share/virtualenvs/pmm-morpheus-migrations-nfisJWJS/bin/python)
  jinja version = 3.1.2
  libyaml = True
```

##### COLLECTION VERSION
<!--- Paste verbatim output from "ansible-galaxy collection list <namespace>.<collection>"  between the quotes
for example: ansible-galaxy collection list community.general
-->
```paste below
# /Users/michaelgaruccio/.local/share/virtualenvs/pmm-morpheus-migrations-nfisJWJS/lib/python3.9/site-packages/ansible_collections
Collection       Version
---------------- -------
community.vmware 3.2.0  
```

##### CONFIGURATION
<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```paste below
CONFIG_FILE() = /Users/michaelgaruccio/code/pmm-morpheus-migrations/ansible.cfg
DEFAULT_STDOUT_CALLBACK(/Users/michaelgaruccio/code/pmm-morpheus-migrations/ansible.cfg) = yaml
```

##### OS / ENVIRONMENT
<!--- Provide all relevant information below, e.g. target OS versions, network device firmware, etc. -->
Running from a MacOS host machine, targeting a variety of different vSphere environments, mostly 7.0+

##### STEPS TO REPRODUCE
<!--- Describe exactly how to reproduce the problem, using a minimal test-case -->
Install the latest version of pyvmomi and attempt to run any task via the vmware_tools connection plugin

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: test failing plugin
  hosts: target_machines
  gather_facts: yes
  connection: community.vmware.vmware_tools
  vars:
    ansible_vmware_user: "{{ vsphere_username }}"
    ansible_vmware_password: "{{ vsphere_password }}"
    ansible_vmware_host: "{{ vsphere_hostname }}"
    ansible_vmware_validate_certs: no
    ansible_vmware_tools_user: "{{ domain_username }}"
    ansible_vmware_tools_password: "{{ domain_password }}"

  tasks:
    - name: Print script
      ansible.builtin.debug:
        msg: test
```

<!--- HINT: You can paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- Describe what you expected to happen when running the steps above -->
Expected for the plugin to work correctly

##### ACTUAL RESULTS
<!--- Describe what actually happened. If possible run with extra verbosity (-vvvv) -->
The plugin fails to import the no-longer existent `SmartConnectNoSSL`
<!--- Paste verbatim command output between quotes -->
```paste below
 Failed to import the required Python library (PyVmomi) on michaels-MacBook-Pro.local's Python /Users/michaelgaruccio/.local/share/virtualenvs/pmm-morpheus-migrations-nfisJWJS/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter : Traceback (most recent call last):
      File "/Users/michaelgaruccio/.ansible/collections/ansible_collections/community/vmware/plugins/connection/vmware_tools.py", line 231, in <module>
        from pyVim.connect import Disconnect, SmartConnect, SmartConnectNoSSL
    ImportError: cannot import name 'SmartConnectNoSSL' from 'pyVim.connect' (/Users/michaelgaruccio/.local/share/virtualenvs/pmm-morpheus-migrations-nfisJWJS/lib/python3.9/site-packages/pyVim/connect.py)
```

The release notes of pyvmomi call this out as a breaking change, and provide a solution



Discussion:
Files identified in the description:
* [`lib/ansible/plugins/connection`](https://github.com/['ansible-collections/amazon.aws', 'ansible-collections/community.aws', 'ansible-collections/community.vmware']/blob/main/lib/ansible/plugins/connection)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->

Resolving patch:
diff --git a/plugins/connection/vmware_tools.py b/plugins/connection/vmware_tools.py
--- a/plugins/connection/vmware_tools.py
+++ b/plugins/connection/vmware_tools.py
@@ -229,7 +229,7 @@
 from ansible.module_utils.basic import missing_required_lib
 
 try:
-    from pyVim.connect import Disconnect, SmartConnect, SmartConnectNoSSL
+    from pyVim.connect import Disconnect, SmartConnect
     from pyVmomi import vim, vmodl
 
     HAS_PYVMOMI = True
@@ -292,15 +292,13 @@ def _establish_connection(self):
             "port": self.get_option("vmware_port"),
         }
 
-        if self.validate_certs:
-            connect = SmartConnect
-        else:
+        if not self.validate_certs:
             if HAS_URLLIB3:
                 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
-            connect = SmartConnectNoSSL
+            connection_kwargs['disableSslCertValidation'] = True
 
         try:
-            self._si = connect(**connection_kwargs)
+            self._si = SmartConnect(**connection_kwargs)
         except SSLError:
             raise AnsibleError("SSL Error: Certificate verification failed.")
         except (gaierror):


Test patch: