This playbook upgrades Debian/Ubuntu servers, then generates a HTML report. The playbook also sends an e-mail with the report as an attachment. The e-mail body states which hosts were updated/failed during the update/were missing when the playbook was running. The HTML report shows the apt-get upgrade output and the updated or deleted packages.
The report is based on jwkenney's ansible-job-report repo. It is pure HTML + CSS without external dependencies and fully editable through the j2 templates and stylesheets. Please check his repo to further information regarding how to customize the report.
Tested with Ansible 2.9 to upgrade Debian 10/11 and Ubuntu 18.04/20.04/22.04 servers.
ansible-server-upgrade-report/
├── upgrade_servers_send_report.yaml
├── README.md
├── reports
└── templates
├── job_report_host.j2
├── job_report_master.j2
└── stylesheet.css.j2
upgrade_servers_send_report
: The main playbook (upgrade servers and generate report)reports/
: The default save location for HTML reportstemplates/job_report_master.j2
: The main HTML report templatetemplates/job_report_host.j2
: A report fragment that provides per-host job detailstemplates/stylesheet.css.j2
: Contains CSS stylesheet info, pulled into the master template.
- Please ensure you have configured SSH keys and you have permissions to upgrade the destination hosts, otherwise the playbook execution will fail.
- See the following sections/variables under
upgrade_servers_and_send_reports.yaml
hosts:
Using the --extra-vars parameter when running the playbook you may select a host_group (if you have defined so in your Ansible's hosts file). Otherwise, the playbook will attempt to upgrade ALL your hosts!vars:
section of the playbook:- Mail reports are enabled by default. Fill in data for your company's mail server (
smtp_user
andsmtp_pass
are optional).
- Mail reports are enabled by default. Fill in data for your company's mail server (
- To modify the predefined template or check additional options, please review jwkenney's ansible-job-report. His repo is very well-documented.
- After testing the playbook, you may add a cron task to automatically upgrade your servers.