how do I email results that are easy to read and confirm each member was added successfully?

23 views
Skip to first unread message

Dennis Levens

unread,
Apr 18, 2019, 10:48:25 PM4/18/19
to Ansible Project
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: fr...@email.com
        to: t...@email.com
      delegate_to: localhost
      become: false



Brian Coca

unread,
Apr 22, 2019, 10:35:20 PM4/22/19
to Ansible Project
Create a template that formats it nicely and use:

body: '{{lookup("template", "pretty_email.j2")}}'

You could try to do the same inline, but it ends up making the task
hard to read and update.
--
----------
Brian Coca

Dennis Levens

unread,
Apr 29, 2019, 5:51:18 PM4/29/19
to Ansible Project
Thanks Brian, I will look into this option :)
Reply all
Reply to author
Forward
0 new messages