Sending the list of available updates via email

125 views
Skip to first unread message

Raza Suleman

unread,
Jan 28, 2022, 6:59:14 PM1/28/22
to Ansible Project
HI,

I would like to create a playbook that will send a list of available yum updates in the message body. How do I do that? my play book has two parts. first it collects a list of available packages and then 2nd it sends an email... I would like to include the results from first part in a readable format as message body in my email. Any help or guidance will be appreciated.
``` Here is my playbook. --- - name: List and return yum update packages hosts: all,!localhost tasks: - name: List available packages and register result to print with debug later yum: list: updates register: result - name: Print return information from the previous task debug: var: result verbosity: 1 - name: send email hosts: localhost tasks: - name: Sending an e-mail using SMTP server mail: host: smtp.domain.local port: 587 username: "{{ mail_username }}" password: "{{ mail_password }}" from: "{{ email_address}}" to: "{{ recipent }}" subject: Patch-report body: Available Patches as of {{ ansible_date_time.date }} delegate_to: localhost run_once: true


_______________________________
Thank you

Raza

Roberto Paz

unread,
Jan 31, 2022, 10:16:11 AM1/31/22
to Ansible Project
I tried stuff like that before using a block or multiline approach for the body attribute:


Maybe you can concatenate the lines of the command output in a previous step using '\n' as EoL and save it into a variable. Then you can use that variable as part of the body.


Reply all
Reply to author
Forward
0 new messages