Connection refused when sending mail with ansible

I am running ansible on a macbook pro. when i use mail Mod like this…

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.Mackenzie@company.com”, “charset”: “utf8”, “from”: “Colin.Mackenzie@company.com”, “headers”: null, “host”: “localhost”, “password”: null, “port”: “25”, “sender”: “blah.Blah@company.com”, “subject”: Compnay WFI Report – Automated email", “subtype”: “plain”, “to”: “Blah2.Blah0@company.com, Blah1.Blah1@company.com, Blah2.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.mackenzie@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

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

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

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).