Skip to content

Instantly share code, notes, and snippets.

@canit00
Forked from halberom/mail_body.j2
Created February 6, 2019 17:36
Show Gist options
  • Save canit00/4ab58ce1972c76327fb61c64979b3742 to your computer and use it in GitHub Desktop.
Save canit00/4ab58ce1972c76327fb61c64979b3742 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