From 8957a84738863a80f8fc0cc5481509be7b80157c Mon Sep 17 00:00:00 2001 From: Baptiste Agasse Date: Wed, 24 May 2023 22:00:07 +0200 Subject: [PATCH] Related #13336 - DNS resolution is preventing awx_collection to work with http[s]_proxy (#13524) Co-authored-by: Seth Foster --- awx_collection/plugins/module_utils/controller_api.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/awx_collection/plugins/module_utils/controller_api.py b/awx_collection/plugins/module_utils/controller_api.py index ef11a74bec..041642067d 100644 --- a/awx_collection/plugins/module_utils/controller_api.py +++ b/awx_collection/plugins/module_utils/controller_api.py @@ -17,7 +17,7 @@ import time import re from json import loads, dumps from os.path import isfile, expanduser, split, join, exists, isdir -from os import access, R_OK, getcwd +from os import access, R_OK, getcwd, environ try: @@ -131,9 +131,11 @@ class ControllerModule(AnsibleModule): self.url.hostname.replace(char, "") # Try to resolve the hostname try: - addrinfolist = getaddrinfo(self.url.hostname, self.url.port, proto=IPPROTO_TCP) - for family, kind, proto, canonical, sockaddr in addrinfolist: - sockaddr[0] + proxy_env_var_name = "{0}_proxy".format(self.url.scheme) + if not environ.get(proxy_env_var_name) and not environ.get(proxy_env_var_name.upper()): + addrinfolist = getaddrinfo(self.url.hostname, self.url.port, proto=IPPROTO_TCP) + for family, kind, proto, canonical, sockaddr in addrinfolist: + sockaddr[0] except Exception as e: self.fail_json(msg="Unable to resolve controller_host ({1}): {0}".format(self.url.hostname, e))