diff --git a/changelogs/fragments/10491-irc.yml b/changelogs/fragments/10491-irc.yml new file mode 100644 index 0000000000..74867e71a7 --- /dev/null +++ b/changelogs/fragments/10491-irc.yml @@ -0,0 +1,2 @@ +bugfixes: + - "irc - pass hostname to ``wrap_socket()`` if ``use_tls=true`` and ``validate_certs=true`` (https://github.com/ansible-collections/community.general/issues/10472, https://github.com/ansible-collections/community.general/pull/10491)." diff --git a/plugins/modules/irc.py b/plugins/modules/irc.py index 1318804fcd..60112ac0de 100644 --- a/plugins/modules/irc.py +++ b/plugins/modules/irc.py @@ -232,9 +232,11 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if use_tls: + kwargs = {} if validate_certs: try: context = ssl.create_default_context() + kwargs["server_hostname"] = server except AttributeError: raise Exception('Need at least Python 2.7.9 for SSL certificate validation') else: @@ -244,7 +246,7 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k else: context = ssl.SSLContext() context.verify_mode = ssl.CERT_NONE - irc = context.wrap_socket(irc) + irc = context.wrap_socket(irc, **kwargs) irc.connect((server, int(port))) if passwd: