I’m running a simple playbook to report on server configurations which is formatted into an html file from a template. I use the mail module to attach the html file into the body of the mail as follows:
- hosts: localhost
tasks:
- name: Send e-mail
local_action: mail
port=25
headers=“Content-type=text/html”
subtype=html
from="xxx@xxx.com"
to="xxx@xxx.com"
subject=‘Server Report’
body=“{{ lookup(‘file’, ‘/tmp/report.html’) }}”
When I run this on a group of 13/14 servers the play runs fine, mail is sent and received as expected. I’ve not seen this with any other playbooks or roles I have on the same server. If I add more servers to the group, the initial parts of the playbook run fine, but it fails as follows:
TASK [Send e-mail] *******************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: socket.error: [Errno 111] Connection refused
fatal: [localhost → localhost]: FAILED! => {“changed”: false, “module_stderr”: “Traceback (most recent call last):\n File "/tmp/ansible_TNdcry/ansible_module_mail.py", line 386, in \n main()\n File "/tmp/ansible_TNdcry/ansible_module_mail.py", line 257, in main\n code, smtpmessage = smtp.connect(host, port=port)\n File "/usr/lib64/python2.6/smtplib.py", line 300, in connect\n self.sock = self._get_socket(host, port, self.timeout)\n File "/usr/lib64/python2.6/smtplib.py", line 278, in _get_socket\n return socket.create_connection((port, host), timeout)\n File "/usr/lib64/python2.6/socket.py", line 567, in create_connection\n raise error, msg\nsocket.error: [Errno 111] Connection refused\n”, “module_stdout”: “”, “msg”: “MODULE FAILURE”, “rc”: 1}
/var/log/messages shows the following abrtd errors which appear to come from python and ansible_module_mail.py:
Mar 5 17:45:13 <masked_server_name> abrt: [ID - user.info] detected unhandled Python exception in ‘/tmp/ansible_TNdcry/ansible_module_mail.py’
Mar 5 17:45:14 <masked_server_name> abrtd: [ID - daemon.err] Directory ‘pyhook-2018-03-05-17:45:14-17875’ creation detected
Mar 5 17:45:14 <masked_server_name> abrt-server[18081]: [ID - daemon.err] Saved Python crash dump of pid 17875 to /var/spool/abrt/pyhook-2018-03-05-17:45:14-17875
What I don’t know is whether this is ansible and/or python, or perhaps my poor implementation of the mail module. Google search has not returned any worthy suggestions or causes. Could I be missing something server side - python config or sendmail?
Does anyone have any ideas?
-Simon