Skip to content

Commit

Permalink
Replace gethostbyname to getaddrinfo for plugins ipv6 support related a…
Browse files Browse the repository at this point in the history
  • Loading branch information
konono and yukiy authored Aug 22, 2022
1 parent db2649d commit dba33f9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions awx_collection/plugins/module_utils/controller_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlencode
from ansible.module_utils.six.moves.configparser import ConfigParser, NoOptionError
from distutils.version import LooseVersion as Version
from socket import gethostbyname
from socket import getaddrinfo, IPPROTO_TCP
import time
import re
from json import loads, dumps
Expand Down Expand Up @@ -138,12 +138,17 @@ def __init__(self, argument_spec=None, direct_params=None, error_callback=None,
except Exception as e:
self.fail_json(msg="Unable to parse controller_host as a URL ({1}): {0}".format(self.host, e))

# Remove ipv6 square brackets
remove_target = '[]'
for char in remove_target:
self.url.hostname.replace(char, "")
# Try to resolve the hostname
hostname = self.url.netloc.split(':')[0]
try:
gethostbyname(hostname)
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(hostname, e))
self.fail_json(msg="Unable to resolve controller_host ({1}): {0}".format(self.url.hostname, e))

def build_url(self, endpoint, query_params=None):
# Make sure we start with /api/vX
Expand Down

0 comments on commit dba33f9

Please sign in to comment.