-
-
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
This file contains hidden or 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 hidden or 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: [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