Once the task is run against all the hosts, how can I log {{ansible_hostname}} and a successful message (wherever the task completed successfully) in the playbook and send that in a single email body? Thanks!
Once the task is run against all the hosts, how can I log
{{ansible_hostname}} and a successful message (wherever the task completed
successfully) in the playbook and send that in a single email body? Thanks!
Try this. The body is a dictionary of all hosts and 'emSt' values.
Fit the attributes to your needs
Thanks! However, that sends multiple emails from the playbook which is not what we are looking for. We expect to get a single summary email from playbook (after tasks are executed) with all the {{ inventory_hostname}} in the body of the email or a file containing the {{ inventory_hostname}} as an attachment to the email.
Thanks! However, that sends multiple emails from the playbook which is not what we are looking for. We expect to get a
single summary email from playbook (after tasks are executed) with all the {{ inventory_hostname}} in the body of the
email or a file containing the {{ inventory_hostname}} as an attachment to the email.
You better use the advice from Vladimir Botka:
--- snip ---
Try this. The body is a dictionary of all hosts and 'emSt' values.
Fit the attributes to your needs
Thanks Racke! As mentioned earlier, the emSt variable doesn’t contain any hostname details in it, so not sure if we can extract that from Vladimir’s sample code. Instead of using the emSt variable in the mail body, can we have the name of all the hosts (where the prior Ansible task was completed to start the OEM agent) and a message saying that “EM agent is started successfully” on the body of the summary email? Something like “EM agent is successfully started on {{ ansible_hostname}}” for all the hosts where the prior playbook task was executed.