Issue
Regarding monthly patching, we currently have an pre_task mail notification sent out prior to the updates being installed but due to the {{ inventory_hostname }} being included in the body of the email, this is sent out on a per server basis.
Is there a way to replace the inventory_hostname in the body to reference all servers within the hosts group (in this case groupOne) so that one email is sent out with all hostnames rather than individual emails?
hosts: groupOne
become: true
any_errors_fatal: true
pre_tasks:
name: Notification email of patching beginning
mail:
host: XXXXXXXXXXXXXXXXXXXXX.com
port: XXXXXX
to: [email protected]
sender: [email protected]
subject: Patching_Notification
body: "Monthly patching is about to commence for {{ inventory_hostname }}. A further email will be sent on completion"
Solution
You can use the group_names
variable to get the group name(s) of your host.
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#magic
You probably want to run your pre_tasks notification only once with run_once: yes
.
Answered By - sebthebert Answer Checked By - Timothy Miller (WPSolving Admin)