From f0fd6aa97d0dd6a5979fc9e262ce38688e2df4f4 Mon Sep 17 00:00:00 2001 From: Boik Date: Tue, 14 Feb 2023 04:36:09 +0800 Subject: [PATCH] Suppress urllib3 InsecureRequestWarnings when `validate_certs` option is false (#5931) * Suppress urllib3 InsecureRequestWarnings when validate_certs option is false Suppress urllib3 InsecureRequestWarnings when `validate_certs` option is false. It's clear that the user would know the possible risk when he or she chose to turn off the option, so the warning message could be ignored and make the output clean. * Create 5915-suppress-urllib3-insecure-request-warnings.yml * Update changelogs/fragments/5915-suppress-urllib3-insecure-request-warnings.yml Co-authored-by: Felix Fontein * Remove extra whitespaces --------- Co-authored-by: Felix Fontein --- .../5915-suppress-urllib3-insecure-request-warnings.yml | 2 ++ plugins/inventory/proxmox.py | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 changelogs/fragments/5915-suppress-urllib3-insecure-request-warnings.yml diff --git a/changelogs/fragments/5915-suppress-urllib3-insecure-request-warnings.yml b/changelogs/fragments/5915-suppress-urllib3-insecure-request-warnings.yml new file mode 100644 index 0000000000..9fa285154a --- /dev/null +++ b/changelogs/fragments/5915-suppress-urllib3-insecure-request-warnings.yml @@ -0,0 +1,2 @@ +minor_changes: + - proxmox - suppress urllib3 ``InsecureRequestWarnings`` when ``validate_certs`` option is ``false`` (https://github.com/ansible-collections/community.general/pull/5931). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index e33f7ed77d..dc2e1febca 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -277,6 +277,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): credentials = urlencode({'username': self.proxmox_user, 'password': self.proxmox_password, }) a = self._get_session() + + if a.verify is False: + from requests.packages.urllib3 import disable_warnings + disable_warnings() + ret = a.post('%s/api2/json/access/ticket' % self.proxmox_url, data=credentials) json = ret.json()