VMware: vmware_tools tls warning fixes (#55187)

* vmware_tools: remove silence_tls_warnings option

* attempt import of bundled urllib3
pull/55272/head
James Cassell 6 years ago committed by Abhijeet Kasurde
parent 36ab96e4a9
commit 7191d45885

@ -12,14 +12,6 @@ from ssl import SSLError
from time import sleep from time import sleep
import traceback 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 REQUESTS_IMP_ERR = None
try: try:
import requests import requests
@ -28,6 +20,16 @@ except ImportError:
REQUESTS_IMP_ERR = traceback.format_exc() REQUESTS_IMP_ERR = traceback.format_exc()
HAS_REQUESTS = False 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.errors import AnsibleError, AnsibleFileNotFound, AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes, to_native from ansible.module_utils._text import to_bytes, to_native
from ansible.plugins.connection import ConnectionBase from ansible.plugins.connection import ConnectionBase
@ -109,13 +111,6 @@ DOCUMENTATION = """
- name: ansible_vmware_validate_certs - name: ansible_vmware_validate_certs
default: True default: True
type: bool 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: vm_path:
description: description:
- VM path absolute to the connection. - VM path absolute to the connection.
@ -180,7 +175,6 @@ ansible_vmware_host: vcenter.example.com
ansible_vmware_user: administrator@vsphere.local ansible_vmware_user: administrator@vsphere.local
ansible_vmware_password: Secr3tP4ssw0rd!12 ansible_vmware_password: Secr3tP4ssw0rd!12
ansible_vmware_validate_certs: no # default is yes ansible_vmware_validate_certs: no # default is yes
ansible_vmware_silence_tls_warnings: yes # default is yes
# vCenter Connection VM Path Example # vCenter Connection VM Path Example
ansible_vmware_guest_path: DATACENTER/vm/FOLDER/{{ inventory_hostname }} ansible_vmware_guest_path: DATACENTER/vm/FOLDER/{{ inventory_hostname }}
@ -297,7 +291,7 @@ class Connection(ConnectionBase):
if self.validate_certs: if self.validate_certs:
connect = SmartConnect connect = SmartConnect
else: else:
if HAS_URLLIB3 and self.get_option("silence_tls_warnings"): if HAS_URLLIB3:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
connect = SmartConnectNoSSL connect = SmartConnectNoSSL

Loading…
Cancel
Save