From 886d4a6596c3e99f4d9351ec4913ce95a2d8d74b Mon Sep 17 00:00:00 2001 From: Mikhail Vorontsov <52924343+mephs@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:02:34 +0300 Subject: [PATCH] proxmox inventory: fix urllib3 InsecureRequestWarnings not suppressing when a token is used (#9099) * proxmox inventory: fix urllib3 InsecureRequestWarnings not suppressing when a token is used * proxmox inventory: add changelog fragment * proxmox inventory: add forgotten pr number * Update changelog. --------- Co-authored-by: Felix Fontein --- changelogs/fragments/9099-proxmox-fix-insecure.yml | 2 ++ plugins/inventory/proxmox.py | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/9099-proxmox-fix-insecure.yml diff --git a/changelogs/fragments/9099-proxmox-fix-insecure.yml b/changelogs/fragments/9099-proxmox-fix-insecure.yml new file mode 100644 index 0000000000..b277a0f933 --- /dev/null +++ b/changelogs/fragments/9099-proxmox-fix-insecure.yml @@ -0,0 +1,2 @@ +minor_changes: + - proxmox inventory plugin - fix urllib3 ``InsecureRequestWarnings`` not being suppressed when a token is used (https://github.com/ansible-collections/community.general/pull/9099). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index d7e2107719..3ce4f789a3 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -276,16 +276,18 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): def _get_auth(self): + validate_certs = self.get_option('validate_certs') + + if validate_certs is False: + from requests.packages.urllib3 import disable_warnings + disable_warnings() + if self.proxmox_password: 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()