Skip to content

Instantly share code, notes, and snippets.

@richardsonlima
Forked from halberom/mail_body.j2
Created April 10, 2020 05:18
Show Gist options
  • Save richardsonlima/4c57ef5baef88fe31b99867216f28c9b to your computer and use it in GitHub Desktop.
Save richardsonlima/4c57ef5baef88fe31b99867216f28c9b to your computer and use it in GitHub Desktop.
ansible - example of using mail module to send one email for all hosts
# templates/mail_body.j2
{% for host in play_hosts %}
The {{ host }} says {{ hostvars[host]['result']['stdout'] }}
{% endfor %}
---
- hosts: all
gather_facts: False
connection: local
tasks:
- shell: echo "hello"
register: result
- mail:
host: example.com
port: 25
to: [email protected]
subject: Test
body: "{{ lookup('template', 'templates/mail_body.j2') }}"
delegate_to: localhost
run_once: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment