ansible-collections / ansible.netcommon

Ansible Network Collection for Common Code
GNU General Public License v3.0
144 stars 104 forks source link

Waiting for terminal_initial_prompt #381

Open felixblang opened 2 years ago

felixblang commented 2 years ago
SUMMARY

I am trying to connect to a network switch through a console server. For this i'm establishing a ssh connection to the console server and going through prompts to connect to the right serial port. once i connect to the serial port though the network_cli module seems to be still waiting for a prompt. Due to the nature of serial connetions there is no prompt and the connection times out without executing any tasks on the host.

ISSUE TYPE
COMPONENT NAME

network_cli

ANSIBLE VERSION
ansible [core 2.11.6]
python version = 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
jinja version = 3.0.2
COLLECTION VERSION
community.general 3.8.0
CONFIGURATION
ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True
DEPRECATION_WARNINGS(/etc/ansible/ansible.cfg) = False
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT

Cisco IOS XE Software, Version 16.12.05b

STEPS TO REPRODUCE

use an opengear console server to foreward an ssh session to a serial port in the format

ssh ansible@opengear.server -p 3001

to connect to the switch on serial port 1 and execute any playbook using this connection.

cisco.ios.ios_config: 
    backup_options:
      dir_path: "{{ localpath.path }}"
      filename: "{{ inventory_hostname }}.cfg"
    backup: true
EXPECTED RESULTS

ansible should execute tasks on the host

ACTUAL RESULTS

ansible times out waiting for a prompt from the connection. the tasks actually run if a prompt is generated by manually forcing a newline on the serial console while ansible is waiting to time out

TASK [backupconfig : BACKUP RUNNING-CONFIG IOS] ***************************************************************************************************
fatal: [C3650-2]: FAILED! => {"changed": false, "msg": "command timeout triggered, timeout value is 30 secs.
See the timeout setting options inteN the Network Debug and Troubleshooting Guide."}
craized commented 1 year ago

I jumped the gun and created a pull request for a workaround I had just intended to propose here. I have been using this implementation adjustment in my own environment to circumvent this problem.

My fix for this issue is introducing an optional network_cli option coax_prompt that will send a newline after making a successful connection. The referenced pull request above has this behavior implemented if anyone wants a short term solution.