From 7191d4588563107a19def557dc4b439e01c80fda Mon Sep 17 00:00:00 2001 From: James Cassell Date: Sun, 14 Apr 2019 10:28:45 -0400 Subject: [PATCH] VMware: vmware_tools tls warning fixes (#55187) * vmware_tools: remove silence_tls_warnings option * attempt import of bundled urllib3 --- .../plugins/connection/vmware_tools.py | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) 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