Well, tried it (generated an app password) but still getting the same 
error. I cannot seem to send any email via Ansible - tried just a simple 
one (no the loop that was suggested) without success. Tried my local 
mail-server as sender - again no success.
Also in the app password page of my google account, I see that "last used" 
column is empty - as if I have never used the pass.
Any suggestions?

On Tuesday, September 15, 2020 at 3:58:39 PM UTC+3 [email protected] 
wrote:

> Believe me, I work for google (not gmail). Google generally doesn’t permit 
> you to use the password directly. You must generate an app password for the 
> third party application.
>
> Thanks 
>
>
> On Tue, Sep 15, 2020 at 8:45 PM Sandy Toshev <[email protected]> wrote:
>
>>
>> I do not understand your suggestion. I am using my gmail account password 
>> in the .yml file. Am I supposed to use some other?
>> On Tuesday, September 15, 2020 at 3:41:33 PM UTC+3 [email protected] 
>> wrote:
>>
>>> You could generate the app specific password for gmail and use it to try 
>>> again.
>>>
>>> Thanks 
>>>
>>> On Tue, Sep 15, 2020 at 8:36 PM Sandy Toshev <[email protected]> wrote:
>>>
>>>>
>>>> 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
>>>>  
>>>> <https://groups.google.com/d/msgid/ansible-project/e8a857a0-0709-4577-807b-da88fe1a489bn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>>
>>
>>
>>
>> -- 
>>
>>
>> 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/869501f0-d04e-4ac7-98b8-ada2e28a644fn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/869501f0-d04e-4ac7-98b8-ada2e28a644fn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>>

-- 
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/69718eda-8c61-431e-a8c3-b066499b45f9n%40googlegroups.com.

Reply via email to