Thank you for the fast response,
So I added the following at the end of the .yml file, but I guess I do not
know the correct syntax, because I get an error.
#added from suggestion
- name: Sending an email about it
mail:
body: |
Deleted some files - {% for f in files_to_delete.files %}f, {% endfor
%}
subject: Deleted files overview
host: smtp.gmail.com
port: 587
username: [email protected]
password: my_very_secure_password
to: my_private_username@my_private_domain
===
The error is as follows:
ERROR! We were unable to read either as JSON nor YAML, these are the errors
we got from each:
JSON: Expecting value: line 1 column 1 (char 0)
Syntax Error while loading YAML.
could not find expected ':'
The error appears to be in '/root/ansible_playbooks/remove_distfiles.yml':
line 21, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
Deleted some files - {% for f in files_to_delete.files %}f, {% endfor
%}
subject: Deleted files overview
^ here
On Tuesday, September 15, 2020 at 3:15:02 PM UTC+3 [email protected] wrote:
> 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/e8a857a0-0709-4577-807b-da88fe1a489bn%40googlegroups.com.