ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
838 stars 1.54k forks source link

mail module gives generic error #7122

Open jmsalvador2395 opened 1 year ago

jmsalvador2395 commented 1 year ago

Summary

When getting a "connection refused error", the module simply tells the user to refer to the stack trace when the error could just be presented in the message itself.

Issue Type

Bug Report

Component Name

mail

Ansible Version

$ ansible --version
ansible [core 2.14.5]
  config file = None
  configured module search path = ['/home/john/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /data/john/projects/cf/env/lib/python3.10/site-packages/ansible
  ansible collection location = /home/john/.ansible/collections:/usr/share/ansible/collections
  executable location = /data/john/projects/cf/env/bin/ansible
  python version = 3.10.11 (main, Apr 20 2023, 19:02:41) [GCC 11.2.0] (/data/john/projects/cf/env/bin/python)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 6.6.0  

# /home/john/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 7.2.0  

Configuration

$ ansible-config dump --only-changed
CONFIG_FILE() = None

OS / Environment

Ubuntu

Steps to Reproduce

---
- name: Test Playbook
  hosts: localhost
  gather_facts: false

  tasks:
    - name: Send Email
      community.general.mail:
        host: 10.1.1.1
        port: "25"
        ehlohost: "localhost"
        sender: test@example.com
        to: [user1@example.com, user2@example.com]
        cc: [cc1@example.com]
        bcc: [bcc1@example.com]
        subject: Test Email
        body: This is a test email
        charset: utf-8
        secure: "never"
        username: test_user
        password: test_password
        timeout: "10"
      register: result

    - name: Print Result
      debug:
        var: result

Expected Results

a message that conveys "connection refused"

Actual Results


0.yaml

ansible-playbook [core 2.14.5]
  config file = None
  configured module search path = ['/home/john/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /data/john/projects/cf/env/lib/python3.10/site-packages/ansible
  ansible collection location = /home/john/.ansible/collections:/usr/share/ansible/collections
  executable location = /data/john/projects/cf/env/bin/ansible-playbook
  python version = 3.10.11 (main, Apr 20 2023, 19:02:41) [GCC 11.2.0] (/data/john/projects/cf/env/bin/python)
  jinja version = 3.1.2
  libyaml = True
No config file found; using defaults
host_list declined parsing /data/john/projects/cf/files/ansible/hosts.ini as it did not pass its verify_file() method
script declined parsing /data/john/projects/cf/files/ansible/hosts.ini as it did not pass its verify_file() method
auto declined parsing /data/john/projects/cf/files/ansible/hosts.ini as it did not pass its verify_file() method
yaml declined parsing /data/john/projects/cf/files/ansible/hosts.ini as it did not pass its verify_file() method
Parsed /data/john/projects/cf/files/ansible/hosts.ini inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: 0.yaml ***************************************************************
1 plays in /data/john/projects/cf/data/module_yaml/20230720-184644/lv2/community.general.mail/0.yaml

PLAY [Test Playbook] ***********************************************************

TASK [Send Email] **************************************************************
task path: /data/john/projects/cf/data/module_yaml/20230720-184644/lv2/community.general.mail/0.yaml:7
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: john
<127.0.0.1> EXEC /bin/sh -c 'echo ~john && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/john/.ansible/tmp `"&& mkdir "` echo /home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503 `" && echo ansible-tmp-1689910662.8156006-77083-94511940485503="` echo /home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503 `" ) && sleep 0'
Using module file /home/john/.ansible/collections/ansible_collections/community/general/plugins/modules/mail.py
<127.0.0.1> PUT /home/john/.ansible/tmp/ansible-local-77079qydco7oo/tmpes1t2x15 TO /home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/ /home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/data/john/projects/cf/env/bin/python /home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py", line 107, in <module>
    _ansiballz_main()
  File "/home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.mail', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.mail', _modlib_path=modlib_path),
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_community.general.mail_payload_nbo2jt2q/ansible_community.general.mail_payload.zip/ansible_collections/community/general/plugins/modules/mail.py", line 418, in <module>
  File "/tmp/ansible_community.general.mail_payload_nbo2jt2q/ansible_community.general.mail_payload.zip/ansible_collections/community/general/plugins/modules/mail.py", line 303, in main
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/smtplib.py", line 341, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/smtplib.py", line 312, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/socket.py", line 845, in create_connection
    raise err
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/socket.py", line 833, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/john/.ansible/tmp/ansible-tmp-1689910662.8156006-77083-94511940485503/AnsiballZ_mail.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.mail', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.mail', _modlib_path=modlib_path),\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.general.mail_payload_nbo2jt2q/ansible_community.general.mail_payload.zip/ansible_collections/community/general/plugins/modules/mail.py\", line 418, in <module>\n  File \"/tmp/ansible_community.general.mail_payload_nbo2jt2q/ansible_community.general.mail_payload.zip/ansible_collections/community/general/plugins/modules/mail.py\", line 303, in main\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/smtplib.py\", line 255, in __init__\n    (code, msg) = self.connect(host, port)\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/smtplib.py\", line 341, in connect\n    self.sock = self._get_socket(host, port, self.timeout)\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/smtplib.py\", line 312, in _get_socket\n    return socket.create_connection((host, port), timeout,\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/socket.py\", line 845, in create_connection\n    raise err\n  File \"/home/john/miniconda3/envs/3.10/lib/python3.10/socket.py\", line 833, in create_connection\n    sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

Code of Conduct

ansibullbot commented 1 year ago

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

ansibullbot commented 1 year ago

cc @dagwieers click here for bot help