ansible.netcommon
ansible.netcommon copied to clipboard
Gns3 iosv telnet
SUMMARY
Add "send_carriage_return" option to send "\r" upon connection similar to existing send-newline. This add ability to connect to IOSv devices in GNS3 which need get the "/r" as the first character in the telnet connection otherwise the prompt is never found. It seem that a carriage return is required to display the NAG banner after which the prompt is output. Issue #542 describes similar issue with nag banner on Procurve switches
ISSUE TYPE
- Bugfix Pull Request
COMPONENT NAME
ansible.netcommon.telnet
ADDITIONAL INFORMATION
Using GNS3 a new project is created with a single IOSv router con0 is made available on 198.18.1.200:500. The last output on the console is "%PLATFORM-5-SIGNATURE_VERIFIED: Image 'flash0:/vios-adventerprisek9-m' passed code signing verification" and the IOSv then waits for a "\r" before display in the NAG and prompt:
- IOSv is strictly limited to use for evaluation, demonstration and IOS *
- education. IOSv is provided as-is and is not supported by Cisco's *
- Technical Advisory Center. Any use or disclosure, in whole or in part, *
- of the IOSv Software or Documentation to any third party for any *
- purposes is expressly prohibited except as otherwise authorized by *
- Cisco in writing. *
Router#
SO using the inventory :- all: hosts: R1: ansible_host: 198.18.1.200 port: 5000 device_type: "cisco_ios_telnet" and playbook :-
- name: Configure hostname using Telnet connection
gather_facts: false
hosts: all
tasks:
- name: Configure hostname telnetX: port: '{{ hostvars[inventory_hostname].port }}' timeout: 5 prompts: - '[>#]' command: - configure terminal - hostname {{ inventory_hostname }}
results in output : (.venv) local@ansible:$ansible-playbook -i ./ansible/inventory/telnetX_hosts.yml ./ansible/telnetX.yml
PLAY [Configure hostname using Telnet connection] ********************************************************************
TASK [Configure hostname] ******************************************************************************************** fatal: [R1]: FAILED! => {"changed": true, "msg": "Telnet timed out trying to find prompt(s): '['[>#]']'", "stdout": "", "stdout_lines": []}
PLAY RECAP *********************************************************************************************************** R1 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
(.venv) local@ansible:$
This is the second run as the first output all the startup output from the device but results in the same behaviour.
With support for sending carriage return and adding send_carriage_return: true send_carriage_return: true to the task :-
- name: Configure hostname using Telnet connection
gather_facts: false
hosts: all
tasks:
- name: Configure hostname telnetX: port: '{{ hostvars[inventory_hostname].port }}' timeout: 5 send_carriage_return: true prompts: - '[>#]' command: - configure terminal - hostname {{ inventory_hostname }}
(.venv) adm-local@ansible:$ansible-playbook -i ./ansible/inventory/telnetX_hosts.yml ./ansible/telnetX.yml
PLAY [Configure hostname using Telnet connection] ********************************************************************
TASK [Configure hostname] ******************************************************************************************** changed: [R1]
PLAY RECAP *********************************************************************************************************** R1 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
(.venv) adm-local@ansible:$
Build failed. https://ansible.softwarefactory-project.io/zuul/buildset/1c57d572d2884f7cb4cddf9cd7bacc58
:x: ansible-test-network-integration-junos-vsrx-netconf-python36-stable29 FAILURE in 12m 51s (non-voting) :heavy_check_mark: ansible-test-network-integration-junos-vsrx-netconf-python36-stable211 SUCCESS in 1h 13m 53s :heavy_check_mark: ansible-test-network-integration-junos-vsrx-netconf-python39-stable212 SUCCESS in 1h 02m 38s :x: ansible-test-network-integration-junos-vsrx-netconf-python39 RETRY_LIMIT in 5m 52s :x: ansible-test-network-integration-junos-vsrx-network_cli-python36-stable29 FAILURE in 12m 16s (non-voting) :heavy_check_mark: ansible-test-network-integration-junos-vsrx-network_cli-python36-stable211 SUCCESS in 16m 59s :heavy_check_mark: ansible-test-network-integration-junos-vsrx-network_cli-python39-stable212 SUCCESS in 14m 40s :x: ansible-test-network-integration-junos-vsrx-network_cli-python39 RETRY_LIMIT in 5m 48s :x: ansible-test-network-integration-junos-vsrx-network_cli-libssh-python36-stable29 FAILURE in 15m 33s (non-voting) :heavy_check_mark: ansible-test-network-integration-junos-vsrx-network_cli-libssh-python36-stable211 SUCCESS in 16m 20s :x: ansible-test-network-integration-junos-vsrx-network_cli-libssh-python39-stable212 FAILURE in 13m 25s :x: ansible-test-network-integration-junos-vsrx-network_cli-libssh-python39 RETRY_LIMIT in 6m 12s :heavy_check_mark: ansible-test-network-integration-nxos-cli-python39-scenario01 SUCCESS in 29m 34s (non-voting) :heavy_check_mark: ansible-test-network-integration-nxos-cli-python39-scenario02 SUCCESS in 28m 22s (non-voting) :x: ansible-test-network-integration-nxos-cli-python39-scenario03 FAILURE in 38m 44s (non-voting) :heavy_check_mark: ansible-test-network-integration-nxos-cli-python39-scenario04 SUCCESS in 25m 42s (non-voting) :x: ansible-test-network-integration-eos-network_cli-python39 RETRY_LIMIT in 6m 28s (non-voting) :x: ansible-test-network-integration-eos-httpapi-python39 RETRY_LIMIT in 5m 18s (non-voting) :x: ansible-test-network-integration-eos-network_cli-libssh-python39 RETRY_LIMIT in 5m 24s (non-voting) :x: ansible-ee-integration-ios-latest FAILURE in 13m 48s (non-voting) :x: ansible-ee-integration-ios-stable-2.9 FAILURE in 12m 47s (non-voting) :x: ansible-ee-integration-ios-stable-2.11 FAILURE in 15m 14s (non-voting) :x: ansible-ee-integration-ios-stable-2.12 FAILURE in 12m 53s (non-voting) :x: ansible-ee-integration-ios-libssh-latest FAILURE in 11m 48s (non-voting) :x: ansible-ee-integration-ios-libssh-stable-2.9 FAILURE in 15m 28s (non-voting) :x: ansible-ee-integration-ios-libssh-stable-2.11 FAILURE in 15m 42s (non-voting) :x: ansible-ee-integration-ios-libssh-stable-2.12 FAILURE in 15m 27s (non-voting) :x: ansible-test-network-integration-vyos-paramiko-python39-devel NODE_FAILURE Node request 200-0006261094 failed in 0s :x: ansible-test-network-integration-vyos-paramiko-python39-stable214 NODE_FAILURE Node request 200-0006261095 failed in 0s :x: ansible-test-network-integration-vyos-paramiko-python39-stable213 NODE_FAILURE Node request 200-0006261096 failed in 0s :x: ansible-test-network-integration-vyos-paramiko-python39-stable212 NODE_FAILURE Node request 200-0006261097 failed in 0s :x: ansible-test-network-integration-vyos-paramiko-python36-stable29 NODE_FAILURE Node request 200-0006261098 failed in 0s (non-voting) :x: ansible-test-network-integration-vyos-libssh-python39-devel NODE_FAILURE Node request 200-0006261099 failed in 0s :x: ansible-test-network-integration-vyos-libssh-python39-stable214 NODE_FAILURE Node request 200-0006261100 failed in 0s :x: ansible-test-network-integration-vyos-libssh-python39-stable213 NODE_FAILURE Node request 200-0006261101 failed in 0s :x: ansible-test-network-integration-vyos-libssh-python39-stable212 NODE_FAILURE Node request 200-0006261102 failed in 0s :x: ansible-test-network-integration-vyos-libssh-python36-stable29 NODE_FAILURE Node request 200-0006261103 failed in 0s :heavy_check_mark: build-ansible-collection SUCCESS in 14m 29s :x: ansible-test-network-integration-ansible-netcommon-junos-vsrx-netconf-python39 RETRY_LIMIT in 5m 59s :heavy_check_mark: ansible-tox-linters SUCCESS in 10m 35s :heavy_check_mark: ansible-galaxy-importer SUCCESS in 5m 03s
I think this is a functional duplicate of https://github.com/ansible-collections/ansible.netcommon/pull/440, do you agree? I feel like an option to change whether explicit carriage returns are used globally is a little clearer, but I'm not sure if there is some reason to only need a carriage return on that first interaction
I think this is a functional duplicate of #440, do you agree? I feel like an option to change whether explicit carriage returns are used globally is a little clearer, but I'm not sure if there is some reason to only need a carriage return on that first interaction
I have tested with ansible.netcommon 5.2.0 and while it does function the terminal output now consists of blank line between every command: R1(config)#line con 0 R1(config-line)# R1(config-line)#transport preferred none R1(config-line)# R1(config-line)#exec-timeout 0 0 R1(config-line)# R1(config-line)#privilege level 15 R1(config-line)# R1(config-line)#logging synchronous R1(config-line)# R1(config-line)#length 60 R1(config-line)# R1(config-line)#width 200 R1(config-line)# R1(config-line)#exit
With the plain send_carriage_return option output is : R1(config)#line con 0 R1(config-line)#transport preferred none R1(config-line)#exec-timeout 0 0 R1(config-line)#privilege level 15 R1(config-line)#logging synchronous R1(config-line)#length 60 R1(config-line)#width 200 R1(config-line)#exit
If I register this output I get reasonably clean output: ok: [R1] => { "con0": { "changed": true, "failed": false, "stdout": "exit\r\nR1#\r\nR1#configure terminal\r\nEnter configuration commands, one per line. End with CNTL/Z.\r\nR1(config)#service password-encryption\r\nR1(config)#\r\n*Sep 11 19:28:52.412: %SYS-5-CONFIG_I: Configured from console by console\r\nR1(config)#line con 0\r\nR1(config-line)#transport preferred none\r\nR1(config-line)#exec-timeout 0 0\r\nR1(config-line)#privilege level 15\r\nR1(config-line)#logging synchronous\r\nR1(config-line)#", "stdout_lines": [ "exit\r\n", "R1#\r\n", "R1#configure terminal\r\n", "Enter configuration commands, one per line. End with CNTL/Z.\r\n", "R1(config)#service password-encryption\r\n", "R1(config)#\r\n", "*Sep 11 19:28:52.412: %SYS-5-CONFIG_I: Configured from console by console\r\n", "R1(config)#line con 0\r\n", "R1(config-line)#transport preferred none\r\n", "R1(config-line)#exec-timeout 0 0\r\n", "R1(config-line)#privilege level 15\r\n", "R1(config-line)#logging synchronous\r\n", "R1(config-line)#" ] } }
But using the crlf method it is a mess and small changes in plays seem to drastically effect what get registered.
I would need test this further but so far the crlf creates more issues for me that it solves.
On a more general theme #440 changes the line ending used throughout the play including changing behavior of the send_newline flag. It seem to me this is doing double duty for two functions that could/should be considered separate. It would be better to have these so in play line ending can be change independent of the send_newline flag which really should just sent "\n". Perhaps a better approach would to have a line_ending option to set the preferred line ending and a separate generic send_on_start where an arbitrary character can be specified upon successful connection to start the terminal session. That way you can have "\r", "\r\n", "\n" or any other characters as the first thing sent.