You can modify the mail task to send per group:
- name: send mail to chetan
mail:
host: relay.services
port: 25
from: [email protected]
to: "{{web_email}}"
subject: uptime for {{item}}
body: |-
{% for server in group_names[item] %}
{% if hostvars[server]['up_time.stdout'] | default (0)
|int >= 5 %}
{{ server }} - {{"has"}}
{{hostvars[server]['up_time.stdout'] }} {{"days uptime. Consider
rebooting for better performance"}}
{% endif %}
{% endfor %}
become: no
loop: ['lab', 'web', 'db']
delegate_to: localhost
run_once: true
Another way, in you existing play change:
hosts: '{{target|default("all")}}'
And create new play:
inorder.yml
- import_playbook: send_mail.yml
vars:
target: lab
- import_playbook: send_mail.yml
vars:
target: web
- import_playbook: send_mail.yml
vars:
target: db
--
----------
Brian Coca
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CACVha7fK7eaF5gdqZJxG6gVqZa92rC3Pju5n4x70AaQJeAuYpQ%40mail.gmail.com.