Use https://docs.ansible.com/ansible/latest/modules/mail_module.html
and set the body argument to an inline jinja template, then iterate
over your "files_to_delete.files" variable.

- name: Sending an email
  mail:
    body: |
      Deleted some files - {% for f in files_to_delete.files %}f, {% endfor %}
    subject: Deleted files overview

etc etc

On Tue, 15 Sep 2020 at 13:55, Sandy Toshev <[email protected]> wrote:
>
> Hi guys,
>
> So I have been using the following simple playbook to keep a folder clean 
> from files. Everything is working fine. However, I got into thinking that it 
> will not hurt, if I get a notification, containing what has been deleted.
> So my question is - may I use the variable into a body of an email? I have 
> tried to view the contents of the registered variable, and I cannot seem to 
> find a way.
> How can I configure an email that will have something like "I have deleted 
> the following files - file1, file2, etc.?
>
> Thank you in advance.
>
> ---
> - hosts: lxc
>   tasks:
>   - name: Finding older than 1 week files in the distfiles folder
>     find:
>       paths: /var/cache/distfiles
>       age: 1w
>       recurse: no
>     register: files_to_delete
>
>   - name: Removing the founded files
>     file:
>       path: "{{ item.path }}"
>       state: absent
>     with_items: "{{ files_to_delete.files }}"
>
> --
> 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/1fd1fcbe-4150-49b8-93c0-9a6aa5879da9n%40googlegroups.com.



-- 
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

-- 
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/CAL8fbwMi_3XXqy0tnbazaTo1aGNpgeccZLmyMYLV3FrF0bS5qg%40mail.gmail.com.

Reply via email to