I didn't google hard enough. This asks the same question, and the has the 
answer, which I'v tried successfully.

https://stackoverflow.com/questions/46992908/ansible-smtp-mail-send

On Sunday, September 6, 2020 at 1:11:03 PM UTC-4 [email protected] wrote:

> $ ansible --version
>
> ansible 2.9.13
>
>   config file = /Users/user/.ansible.cfg
>
>   configured module search path = ['/Users/user/.ansible/plugins/modules', 
> '/usr/share/ansible/plugins/modules']
>
>   ansible python module location = 
> /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible
>
>   executable location = 
> /Library/Frameworks/Python.framework/Versions/3.8/bin/ansible
>
>   python version = 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) [Clang 
> 6.0 (clang-600.0.57)]
>
> I have the following task
>
> # Mail the files
>
> - *name*: Mail the zip file
>
>   *mail*:
>
>     *host*: smtp.gmail.com
>
>     *port*: 465 # 587 fails as well
>
>     *secure*: starttls  # always fails as well
>
>     *charset*: utf-8
>
>     *username*: "{{ user }}"
>
>     *password*: "{{ pw }}"
>
>     *to*: "[email protected]"
>
>     *from*: "[email protected]"
>
>     *subject*: "Private key and CSR files"
>
>     *attach*: "{{ archive_file }}"
>
>     *body*: "Ansible-generated private and CSR files for {{ common_name 
> }}"
>
>   *delegate_to*: localhost
>
>
> I'm very sure I'm passing the correct username and password. However I get 
> this error when I run my playbook.
>
>
> <localhost> ESTABLISH LOCAL CONNECTION FOR USER: user
>
> <localhost> EXEC /bin/sh -c 'echo ~user && sleep 0'
>
> <localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo 
> /Users/user/.ansible/tmp `"&& mkdir "` echo 
> /Users/user/.ansible/tmp/ansible-tmp-1599411608.7587368-75656-16246975542505 
> `" && echo ansible-tmp-1599411608.7587368-75656-16246975542505="` echo 
> /Users/user/.ansible/tmp/ansible-tmp-1599411608.7587368-75656-16246975542505 
> `" ) && sleep 0'
>
> Using module file 
> /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ansible/modules/notification/mail.py
>
> <localhost> PUT 
> /Users/user/.ansible/tmp/ansible-local-75569bryuh8_h/tmp3plwd3_u TO 
> /Users/user/.ansible/tmp/ansible-tmp-1599411608.7587368-75656-16246975542505/AnsiballZ_mail.py
>
> <localhost> EXEC /bin/sh -c 'chmod u+x 
> /Users/user/.ansible/tmp/ansible-tmp-1599411608.7587368-75656-16246975542505/ 
> /Users/user/.ansible/tmp/ansible-tmp-1599411608.7587368-75656-16246975542505/AnsiballZ_mail.py
>  
> && sleep 0'
>
> <localhost> EXEC /bin/sh -c '/usr/bin/python 
> /Users/user/.ansible/tmp/ansible-tmp-1599411608.7587368-75656-16246975542505/AnsiballZ_mail.py
>  
> && sleep 0'
>
> <localhost> EXEC /bin/sh -c 'rm -f -r 
> /Users/user/.ansible/tmp/ansible-tmp-1599411608.7587368-75656-16246975542505/ 
> > /dev/null 2>&1 && sleep 0'
>
> The full traceback is:
>
> WARNING: The below traceback may *not* be related to the actual failure.
>
>   File 
> "/var/folders/rh/bjfb4ltd1mj3_vcv8d82r5j00000gp/T/ansible_mail_payload_5Xv8cx/ansible_mail_payload.zip/ansible/modules/notification/mail.py",
>  
> line 316, in main
>
>   File 
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py",
>  
> line 623, in login
>
>     raise SMTPAuthenticationError(code, resp)
>
> fatal: [localhost]: FAILED! => {
>
>     "changed": false,
>
>     "invocation": {
>
>         "module_args": {
>
>             "attach": [
>
>                 "/tmp/www.example.com.zip"
>
>             ],
>
>             "bcc": [],
>
>             "body": "Ansible-generated private and CSR files for 
> www.example.com",
>
>             "cc": [],
>
>             "charset": "utf-8",
>
>             "from": "[email protected]",
>
>             "headers": [],
>
>             "host": "smtp.gmail.com",
>
>             "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
>
>             "port": 465,
>
>             "secure": "starttls",
>
>             "sender": "[email protected]",
>
>             "subject": "Private key and CSR files",
>
>             "subtype": "plain",
>
>             "timeout": 20,
>
>             "to": [
>
>                 "[email protected]"
>
>             ],
>
>             "username": "[email protected]"
>
>         }
>
>     },
>
>     "rc": 1
>
> }
>
>
> MSG:
>
>
> Authentication to smtp.gmail.com:465 failed, please check your username 
> and/or password
>
>
> PLAY RECAP 
> *********************************************************************
>
> localhost                  : ok=4    changed=0    unreachable=0    
> failed=1    skipped=0    rescued=0    ignored=0
>
>
> What am I missing? I've googled to no avail.
>

-- 
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/17bfc27d-d8b3-4c03-baa5-31236dacdb33n%40googlegroups.com.

Reply via email to