# Ansible Mail Module Failing

**URL:** <https://forum.ansible.com/t/ansible-mail-module-failing/26909>\
**Category:** AWX Project\
**Created:** [March 6, 2018, 11:39am UTC](https://forum.ansible.com/t/ansible-mail-module-failing/26909 "2018-03-06T11:39:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Hayes](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Simon\_Hayes](https://forum.ansible.com/u/Simon_Hayes)\
**Post date:** [March 6, 2018, 11:39am UTC](https://forum.ansible.com/t/ansible-mail-module-failing/26909/1 "2018-03-06T11:39:27Z")

</div>

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](mailto:from=%22xxx@xxx.com)"**  
**[to="xxx@xxx.com](mailto:to=%22xxx@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

---

<div class="post-metadata">

**Author:** ![Simon\_Hayes](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Simon\_Hayes](https://forum.ansible.com/u/Simon_Hayes)\
**Post date:** [March 6, 2018, 11:43am UTC](https://forum.ansible.com/t/ansible-mail-module-failing/26909/2 "2018-03-06T11:43:26Z")

</div>

Forgot to add version details in case that helps:

ansible 2.4.3.0  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.6/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 2.6.6 (r266:84292, Aug 9 2016, 06:11:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

---

<div class="post-metadata">

**Author:** ![matburt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matburt/32/3612_2.png) [@matburt](https://forum.ansible.com/u/matburt)\
**Post date:** [March 6, 2018, 1:53pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing/26909/3 "2018-03-06T13:53:16Z")

</div>

Simon, it seems like you are looking for help with Ansible itself… you may consider visiting their mailing list or irc channel to see if you can get some help there. Having said that… Connection Refused generally means that you have the server wrong or there’s a problem with your network.

---

<div class="post-metadata">

**Author:** ![Simon\_Hayes](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Simon\_Hayes](https://forum.ansible.com/u/Simon_Hayes)\
**Post date:** [March 6, 2018, 2:57pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing/26909/4 "2018-03-06T14:57:39Z")

</div>

Ah - it looks like I put this in the wrong mailing list. Sorry!

---

<div class="post-metadata">

**Author:** ![Meta\_P](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@Meta\_P](https://forum.ansible.com/u/Meta_P)\
**Post date:** [October 8, 2018, 6:40pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing/26909/5 "2018-10-08T18:40:46Z")

</div>

Hi Simon, I have exactly the same problem. Did you figure it out how fix this issue. The problem show up only when I use Ansible AWX to run playbook. There was no problem when I run the Anisble-palybook.

---

<div class="post-metadata">

**Author:** ![Tirumalaraju\_Chandra](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@Tirumalaraju\_Chandra](https://forum.ansible.com/u/Tirumalaraju_Chandra)\
**Post date:** [July 12, 2019, 4:11pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing/26909/6 "2019-07-12T16:11:47Z")

</div>

I have the same issue. Works from command line but **not** awx. Did anyone figure out the fix?

Thanks,  
Chand
