# one email for multiple hosts

**URL:** <https://forum.ansible.com/t/one-email-for-multiple-hosts/35863>\
**Category:** Ansible Project\
**Created:** [October 13, 2021, 8:13pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863 "2021-10-13T20:13:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Raj](https://forum.ansible.com/u/Raj)\
**Post date:** [October 13, 2021, 8:13pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/1 "2021-10-13T20:13:03Z")

</div>

Hi All,

I am trying to send one email to team after job is successfully completed. Issue is playbook sending (if inventory have 100 servers ). It is sending 100 emails.

I tried in my code: delegate\_to: localhost and run\_once: true it doesn’t help please provide your inputs it really helpful .

TIA  
Raja

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [October 14, 2021, 5:27am UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/2 "2021-10-14T05:27:57Z")

</div>

> Hi All,
> 
> I am trying to send one email to team after job is successfully completed. Issue is playbook sending (if inventory have 100 servers ). It is sending 100 emails.
> 
> I tried in my code: delegate\_to: localhost and run\_once: true it doesn't help please provide your inputs it really helpful .

That should work. Please provide your code.

Regards

```
        Racke

```

---

<div class="post-metadata">

**Author:** ![Raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Raj](https://forum.ansible.com/u/Raj)\
**Post date:** [October 14, 2021, 1:12pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/3 "2021-10-14T13:12:24Z")

</div>

Hi Racke,

This is my code

- name: Sending email to about SSL scan  
mail:  
host: xxxxx  
port: 25  
body: xxxx  
to:

# - xxxx

- xxxx  
delegate\_to: localhost  
run\_once: true

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 14, 2021, 2:20pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/4 "2021-10-14T14:20:54Z")

</div>

This is just the one mail task.  
It must be part of a playbook, where other things happen as well, and which will reveal the cause.

Also, you say “I am trying to send one email to team after job is successfully completed”.  
I guess this “job” is the running of the playbook?

---

<div class="post-metadata">

**Author:** ![Raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Raj](https://forum.ansible.com/u/Raj)\
**Post date:** [October 14, 2021, 3:02pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/5 "2021-10-14T15:02:14Z")

</div>

Hi…

Yes it is running in same playbook.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 14, 2021, 3:09pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/6 "2021-10-14T15:09:02Z")

</div>

So, post that playbook

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [October 14, 2021, 3:16pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/7 "2021-10-14T15:16:38Z")

</div>

> Hi Racke,
> 
> This is my code
> 
> - name: Sending email to about SSL scan  
> mail:  
> host: xxxxx  
> port: 25  
> subject: xxxx  
> body: xxxx  
> from: xxx  
> to:  
> # - xxxx  
> - xxxx  
> delegate\_to: localhost  
> run\_once: true

The mail module apparently doesn't check its parameters. For example "from" is going to be ignored, as the correct parameter is "sender". Please double check your indentation. "run\_once" should be working.

Regards

```
  Racke

```

---

<div class="post-metadata">

**Author:** ![Raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Raj](https://forum.ansible.com/u/Raj)\
**Post date:** [October 22, 2021, 2:09pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/8 "2021-10-22T14:09:01Z")

</div>

Hi, VGM

my playbook call roles ssl scan ( final part is email to send once) but it is sending 100 emails

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [October 22, 2021, 2:19pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/9 "2021-10-22T14:19:11Z")

</div>

> Hi, VGM
> 
> my playbook call roles ssl scan ( final part is email to send once) but it is sending 100 emails

Did you ever check the indentation on your task sending email as advised?

delegate\_to should really work.

Regards

```
         Racke

```

---

<div class="post-metadata">

**Author:** ![Raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Raj](https://forum.ansible.com/u/Raj)\
**Post date:** [October 22, 2021, 4:46pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/10 "2021-10-22T16:46:27Z")

</div>

Yes…

No errors email sending included run one and delegate\_to localhost

Thanks

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 22, 2021, 5:55pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/11 "2021-10-22T17:55:24Z")

</div>

So this mail task is part of that role?

---

<div class="post-metadata">

**Author:** ![Raj](https://avatars.discourse-cdn.com/v4/letter/r/c0e974/32.png) [@Raj](https://forum.ansible.com/u/Raj)\
**Post date:** [October 22, 2021, 5:56pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/12 "2021-10-22T17:56:07Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 22, 2021, 6:17pm UTC](https://forum.ansible.com/t/one-email-for-multiple-hosts/35863/13 "2021-10-22T18:17:23Z")

</div>

I think run\_once only works when in a playbook task. Not when it’s buried inside a role
