From 6ef9c2d7b7a8ae2c67a5a86877e1f57e20d84799 Mon Sep 17 00:00:00 2001 From: guoqiao Date: Thu, 23 Aug 2018 18:50:54 +1200 Subject: [PATCH] Fix mail module for python 3.7.0 (#44550) (#44552) In python 3.7.0, changes in `ssl.py` breaks `smtplib.SMTP_SSL`, which then breaks `mail` module in ansible. Run this line in python shell: import smtplib;smtplib.SMTP_SSL().connect(host='smtp.gmail.com', port=465) Before python 3.7.0, we will get: (220, b'smtp.gmail.com ESMTP j13-v6sm3086685pgq.56 - gsmtp') In python 3.7.0, we get such error at `lib/python3.7/ssl.py` line 843, method `_create`: ValueError: server_hostname cannot be an empty string or start with a leading dot. The ssl module is using host info on SMTP_SSL instance, which is not set. The fix/workaround is simple, just pass host info to it: import smtplib;smtplib.SMTP_SSL(host='smtp.gmail.com').connect(host='smtp.gmail.com', port=465) Fixes: #44550 Signed-off-by: Guo Qiao --- changelogs/fragments/44552-mail-py370-compat.yml | 2 ++ lib/ansible/modules/notification/mail.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/44552-mail-py370-compat.yml diff --git a/changelogs/fragments/44552-mail-py370-compat.yml b/changelogs/fragments/44552-mail-py370-compat.yml new file mode 100644 index 00000000000..d72c3b75857 --- /dev/null +++ b/changelogs/fragments/44552-mail-py370-compat.yml @@ -0,0 +1,2 @@ +bugfixes: +- fix mail module for python 3.7.0 (https://github.com/ansible/ansible/pull/44552) diff --git a/lib/ansible/modules/notification/mail.py b/lib/ansible/modules/notification/mail.py index 4598690f878..e1713e90d9e 100644 --- a/lib/ansible/modules/notification/mail.py +++ b/lib/ansible/modules/notification/mail.py @@ -248,7 +248,7 @@ def main(): try: if secure != 'never': try: - smtp = smtplib.SMTP_SSL(timeout=timeout) + smtp = smtplib.SMTP_SSL(host=host, timeout=timeout) code, smtpmessage = smtp.connect(host, port=port) secure_state = True except ssl.SSLError as e: