mail using ansible

387 views
Skip to first unread message

Abhishek Bandari

unread,
Jun 14, 2016, 8:39:52 AM6/14/16
to Ansible Project
email.yml
---
 - hosts: localhost
   tasks:
    - name: sending mail
      mail:
        host: "smtp.gmail.com"
        port: 25
        username: "xxxxxxx...@gmail.com"
        password: "xxxxxxxxxxxxx"
        to: "xxxxxxxx...@gmail.com"
        subject: "Ansible-report"
        body: "Hello, this is an e-mail. I hope you like it ;-)"

This code is fine...but im getting error like this.......I tried 25,465.587 ports

[root@ansible-hyd ~]# ansible-playbook email.yml

PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [sending mail] ************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failed to send mail to server smtp.gmail.com on port 25: [Errno 101] Network is unreachable", "rc": 1}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @email.retry

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1



How to configure...Help me from this...

Kai Stian Olstad

unread,
Jun 14, 2016, 9:47:23 AM6/14/16
to ansible...@googlegroups.com
On 14. juni 2016 08:03, Abhishek Bandari wrote:
> *email.yml*
> ---
> - hosts: localhost
> tasks:
> - name: sending mail
> mail:
> host: "smtp.gmail.com"
> port: 25
> username: "xxxxxxx...@gmail.com"
> password: "xxxxxxxxxxxxx"
> to: "xxxxxxxx...@gmail.com"
> subject: "Ansible-report"
> body: "Hello, this is an e-mail. I hope you like it ;-)"
>
> This code is fine...but im getting error like this.......I tried 25,465.587
> ports

According to the example in the documentation
https://docs.ansible.com/ansible/mail_module.html#examples
it's port 587.

And that's work for me.

>
> [root@ansible-hyd ~]# ansible-playbook email.yml
>
> PLAY [localhost]
> ***************************************************************
>
> TASK [setup]
> *******************************************************************
> ok: [localhost]
>
> TASK [sending mail]
> ************************************************************
> fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg":
> "Failed to send mail to server smtp.gmail.com on port 25: [Errno 101]
> Network is unreachable", "rc": 1}

Do you get the same message with port 587?
If so, are port 587 open for outgoing connections?

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages