Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telnet Module Error Messages #582

Open
jmsalvador2395 opened this issue Aug 8, 2023 · 0 comments
Open

Telnet Module Error Messages #582

jmsalvador2395 opened this issue Aug 8, 2023 · 0 comments

Comments

@jmsalvador2395
Copy link

SUMMARY

Telnet module error should be more explicit about errors during connection establishment. Currently the output is vague

ISSUE TYPE
  • Bug Report
COMPONENT NAME

telnet

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
COLLECTION VERSION
Collection        Version
----------------- -------
ansible.netcommon 4.1.0  

# /home/john/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.netcommon 5.1.2
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT

Ubuntu

STEPS TO REPRODUCE
  1. Execute the example playbook and set target to a machine that does not have telnet enabled (to trigger error message)
---
- name: Test playbook for ansible.netcommon.telnet
  hosts: localhost  # Assuming this playbook will run on the control node
  gather_facts: false

  tasks:
    - name: Execute telnet command
      ansible.netcommon.telnet:
        host: "10.1.1.1"
        port: 23
        user: "admin"
        password: "admin"
        command:
          - "ls"
      register: telnet_output

    - name: Display telnet output
      debug:
        var: telnet_output.stdout_lines
EXPECTED RESULTS

An error message along the lines of Module failed to establish a connection to the target host: <reason>

ACTUAL RESULTS
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
setting up inventory plugins
host_list declined parsing /data/john/projects/cf/data/module_yaml/20230720-184644/lv3/ansible.netcommon.telnet/hosts.ini as it did not pass its verify_file() method
script declined parsing /data/john/projects/cf/data/module_yaml/20230720-184644/lv3/ansible.netcommon.telnet/hosts.ini as it did not pass its verify_file() method
auto declined parsing /data/john/projects/cf/data/module_yaml/20230720-184644/lv3/ansible.netcommon.telnet/hosts.ini as it did not pass its verify_file() method
yaml declined parsing /data/john/projects/cf/data/module_yaml/20230720-184644/lv3/ansible.netcommon.telnet/hosts.ini as it did not pass its verify_file() method
Parsed /data/john/projects/cf/data/module_yaml/20230720-184644/lv3/ansible.netcommon.telnet/hosts.ini inventory source with ini plugin
Loading collection ansible.netcommon from /home/john/.ansible/collections/ansible_collections/ansible/netcommon
Loading callback plugin default of type stdout, v2.0 from /data/john/projects/cf/env/lib/python3.10/site-packages/ansible/plugins/callback/default.py
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: example.yaml *********************************************************
Positional arguments: example.yaml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/data/john/projects/cf/data/module_yaml/20230720-184644/lv3/ansible.netcommon.telnet/hosts.ini',)
forks: 5
1 plays in example.yaml

PLAY [Test playbook for ansible.netcommon.telnet] ******************************

TASK [Execute telnet command] **************************************************
task path: /data/john/projects/cf/data/module_yaml/20230720-184644/lv3/ansible.netcommon.telnet/example.yaml:7
The full traceback is:
Traceback (most recent call last):
  File "/data/john/projects/cf/env/lib/python3.10/site-packages/ansible/executor/task_executor.py", line 158, in run
    res = self._execute()
  File "/data/john/projects/cf/env/lib/python3.10/site-packages/ansible/executor/task_executor.py", line 633, in _execute
    result = self._handler.run(task_vars=vars_copy)
  File "/home/john/.ansible/collections/ansible_collections/ansible/netcommon/plugins/action/telnet.py", line 59, in run
    self.tn = telnetlib.Telnet(host, port, timeout)
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/telnetlib.py", line 218, in __init__
    self.open(host, port, timeout)
  File "/home/john/miniconda3/envs/3.10/lib/python3.10/telnetlib.py", line 235, in open
    self.sock = 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)
OSError: [Errno 113] No route to host
fatal: [localhost]: FAILED! => {
    "msg": "Unexpected failure during module execution: [Errno 113] No route to host",
    "stdout": ""
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant