Skip to content

Instantly share code, notes, and snippets.

@halberom
Created September 7, 2017 09:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save halberom/0aea275632d2b47af0536e5def01d4d2 to your computer and use it in GitHub Desktop.
Save halberom/0aea275632d2b47af0536e5def01d4d2 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: test@example.com
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