Connection refused when sending mail with ansible

991 views
Skip to first unread message

Colin MacKenzie, III

unread,
Jun 2, 2016, 10:04:23 AM6/2/16
to Ansible Project
I am running ansible on a macbook pro. when i use mail Mod like this...

       - name: Send Emails
         local_action: mail
                      subject="Company WFI Report -- Automated email"
                      body="This email is automated contact Colin Mackenzie if you have problems"
                      from="Colin.M...@company.com"
                      to="Blah0...@company.com, Blah1...@company.com, Blah1...@company.com"
                      cc="Colin.M...@company.com"
                      attach='/Users/mackc/ansible/reports/{{ inventory_hostname }}-WFIActiveViewers-{{ filename_date_part  }}.txt'
                      charset=utf8

I get this error:

fatal: [WEBNODE1 -> localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"attach": "/Users/mackc/ansible/reports/WEBNODE1-WFIActiveViewers-20160602124241UTC.txt", "bcc": null, "body": "This email is automated contact Colin Mackenzie if you have problems", "cc": "Colin.M...@company.com", "charset": "utf8", "from": "Colin.M...@company.com", "headers": null, "host": "localhost", "password": null, "port": "25", "sender": "blah...@company.com", "subject": Compnay WFI Report -- Automated email", "subtype": "plain", "to": "Blah2...@company.com, Blah1...@company.com, Blah2...@company.com", "username": null}, "module_name": "mail"}, "msg": "Failed to send mail to server localhost on port 25: [Errno 61] Connection refused", "rc": 1}



I can send email fine from the command line like this:

uuencode /Users/mackc/ansible/reports/areport areport | mail -s "Company Report" colin.m...@company.com


What am i missing so i can send email from ansible playbook i have?
Thanks for anyone taking the time to respond.

-cm3

Johannes Kastl

unread,
Jun 2, 2016, 11:06:37 AM6/2/16
to ansible...@googlegroups.com
On 02.06.16 14:58 Colin MacKenzie, III wrote:

> I can send email fine from the command line like this:
>
> uuencode /Users/mackc/ansible/reports/areport areport | mail -s "Company
> Report" colin.m...@company.com

I think you are using ansible's mail module as a local action, while
on the command line you are using the mail executable. And I guess the
latter works without a fully configured SMTP-server on your macbook...

Can you use the full path to the mail executable in the local_action?
I'll have a look at the docs.

Johannes


signature.asc

Johannes Kastl

unread,
Jun 2, 2016, 11:11:10 AM6/2/16
to ansible...@googlegroups.com
On 02.06.16 17:06 Johannes Kastl wrote:

> Can you use the full path to the mail executable in the local_action?

I guess not.

What happens when you test the following:

- hosts: localhost
become: no
tasks:
- mail: ...

This should send a mail via ansible from your localhost. If this
works, the local_action should also work, I guess.

(Untested)

Johannes

signature.asc

Brian Coca

unread,
Jun 2, 2016, 1:17:12 PM6/2/16
to ansible...@googlegroups.com
The mail command can invoke /usr/bin/sendmail directly and queue w/o having an MTA listening on port 25. The mail module needs a network accessible MTA (mail transfer agent, the software that actually accepts and delivers email).

----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages