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:
        host: myemail.host.com
        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 }}
        from: [email protected]
        to: [email protected]
      delegate_to: localhost
      become: false



-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/01dc9ced-fd9b-43f7-92ad-1fdfb241eda7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to