Created
September 7, 2017 09:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# templates/mail_body.j2 | |
{% for host in play_hosts %} | |
The {{ host }} says {{ hostvars[host]['result']['stdout'] }} | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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