This script is working but the results are difficult to read in the email that is sent.
Ideally I would like the email to say something like:
The following
Add: {{ member }} To: {{ group }} On: {{ ansible_hostname }} [has failed or was successful]
The following are the current members of the group Administrators on {{ ansible_hostname }}
DOM\First_Group
DOM\Second_Group
The data all seems to be in userData but I don't know how to put some smarts to check it was successful and not sure how to list a clean list of the members of the group.
-
hosts: BI
vars:
- group: Administrators
- member:
- DOM\First_Group
- DOM\Second_Group
tasks:
- name: Add a domain user to a local group
win_group_membership:
name: "{{ group }}"
members:
- "{{ item }}"
state: present
with_items: "{{ member }}"
register: userData
- debug:
var: group
- debug:
var: member
- debug:
var: userData
- mail:
port: 25
subject: "Ansible Playbook - Add user to group on {{ ansible_hostname }}"
subtype: html
body: "<h3>Output of Ansible Playbook</h3> Add: {{ member }} <br> To: {{ group }} <br> On: {{ ansible_hostname }} <br><br> Results: {{ userData }}
delegate_to: localhost
become: false