Created
August 1, 2015 13:08
-
-
Save infernix/1f2f2f4e60b8cc97f43b to your computer and use it in GitHub Desktop.
Send one email with vars from a large play
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
- name: Generate log file name | |
hosts: all | |
connection: local | |
tasks: | |
- shell: mktemp | |
register: mktemp | |
always_run: yes | |
run_once: true | |
- name: Write entries to the log file | |
hosts: outdated | |
connection: local | |
serial: 1 | |
tasks: | |
- lineinfile: dest={{ mktemp.stdout }} line="Host {{ inventory_hostname }} was updated at {{ ansible_date_time.date }} {{ ansible_date_time.time }} {{ ansible_date_time.tz }}" create=no state=present | |
always_run: yes | |
- name: Send email with update log | |
hosts: outdated | |
connection: local | |
tasks: | |
- stat: path={{ mktemp.stdout }} | |
register: updatelogcheck | |
always_run: yes | |
run_once: yes | |
- shell: cat {{ mktemp.stdout }} | |
register: mail_body | |
when: updatelogcheck.stat.exists == true | |
always_run: yes | |
run_once: yes | |
mail: subject='Update completed' body='{{ mail_body.stdout }}' from='[email protected] (Your Name)' to='Recipient <[email protected]>' cc='Other Recipient <[email protected]>' | |
when: updatelogcheck.stat.exists == true and mail_body.stdout != "" | |
run_once: yes | |
- file: path={{ mktemp.stdout }} state=absent | |
always_run: yes | |
run_once: yes | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment