From 8448967c74de1d9e2addc3c19717f48e902b0b53 Mon Sep 17 00:00:00 2001 From: James Cassell Date: Sun, 14 Apr 2019 10:28:45 -0400 Subject: [PATCH] [Backport 2.8] VMware: vmware_tools tls warning fixes * vmware_tools: remove silence_tls_warnings option * attempt import of bundled urllib3 (cherry picked from commit 7191d4588563107a19def557dc4b439e01c80fda) --- .../vmware_tools_fix_urllib3_import.yaml | 2 ++ .../plugins/connection/vmware_tools.py | 28 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 changelogs/fragments/vmware_tools_fix_urllib3_import.yaml diff --git a/changelogs/fragments/vmware_tools_fix_urllib3_import.yaml b/changelogs/fragments/vmware_tools_fix_urllib3_import.yaml new file mode 100644 index 00000000000..60c5216250b --- /dev/null +++ b/changelogs/fragments/vmware_tools_fix_urllib3_import.yaml @@ -0,0 +1,2 @@ +minor_changes: +- Try to use bundled urllib3 first, then falls back to non-bundled version in vmware_tools (https://github.com/ansible/ansible/pull/55187). diff --git a/lib/ansible/plugins/connection/vmware_tools.py b/lib/ansible/plugins/connection/vmware_tools.py index 4114f8c6eb0..b38116b0340 100644 --- a/lib/ansible/plugins/connection/vmware_tools.py +++ b/lib/ansible/plugins/connection/vmware_tools.py @@ -12,14 +12,6 @@ from ssl import SSLError from time import sleep import traceback -URLLIB3_IMP_ERR = None -try: - import urllib3 - HAS_URLLIB3 = True -except ImportError: - URLLIB3_IMP_ER = traceback.format_exc() - HAS_URLLIB3 = False - REQUESTS_IMP_ERR = None try: import requests @@ -28,6 +20,16 @@ except ImportError: REQUESTS_IMP_ERR = traceback.format_exc() HAS_REQUESTS = False +try: + from requests.packages import urllib3 + HAS_URLLIB3 = True +except ImportError: + try: + import urllib3 + HAS_URLLIB3 = True + except ImportError: + HAS_URLLIB3 = False + from ansible.errors import AnsibleError, AnsibleFileNotFound, AnsibleConnectionFailure from ansible.module_utils._text import to_bytes, to_native from ansible.plugins.connection import ConnectionBase @@ -109,13 +111,6 @@ DOCUMENTATION = """ - name: ansible_vmware_validate_certs default: True type: bool - silence_tls_warnings: - description: - - Don't output warnings about insecure connections. - vars: - - name: ansible_vmware_silence_tls_warnings - default: True - type: bool vm_path: description: - VM path absolute to the connection. @@ -180,7 +175,6 @@ ansible_vmware_host: vcenter.example.com ansible_vmware_user: administrator@vsphere.local ansible_vmware_password: Secr3tP4ssw0rd!12 ansible_vmware_validate_certs: no # default is yes -ansible_vmware_silence_tls_warnings: yes # default is yes # vCenter Connection VM Path Example ansible_vmware_guest_path: DATACENTER/vm/FOLDER/{{ inventory_hostname }} @@ -297,7 +291,7 @@ class Connection(ConnectionBase): if self.validate_certs: connect = SmartConnect else: - if HAS_URLLIB3 and self.get_option("silence_tls_warnings"): + if HAS_URLLIB3: urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) connect = SmartConnectNoSSL