telnet issue

643 views
Skip to first unread message

Zaldy B

unread,
Apr 13, 2020, 3:07:25 AM4/13/20
to Ansible Project

Hi Experts,

I am just new with this one. I am trying to connect using telnet (ssh has no issue) to my IOS devices, but I am getting error when I run my playbook:


  • name: Telnet do show version for IOS
    hosts: telnet_device
    gather_facts: false
    connection: local

    tasks:

    • name: show version
      telnet:
      user: cisco
      password: cisco
      login_prompt: "Username: "
      prompts:
      - "[>#]"
      command:
      - terminal length 0
      - show version

Error:
PLAY [Telnet do show version for IOS] ***********************************************************************************************************************

TASK [show version] *****************************************************************************************************************************************
fatal: [telnet_device]: FAILED! => {"changed": true, "msg": "Telnet action failed: telnet connection closed", "output": []}

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



Any suggestions/comments is much appreciated.

Zaldy B

unread,
Apr 13, 2020, 3:09:58 AM4/13/20
to Ansible Project
I am getting this when I do -vvv


ansible-playbook 2.8.5
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method
auto declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method
 [WARNING]: Unable to parse /etc/ansible/TEMPLATES/Cisco_IOS as an inventory source
 [WARNING]: No inventory was parsed, only implicit localhost is available
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

Karl Auer

unread,
Apr 13, 2020, 3:23:36 AM4/13/20
to ansible-project
Can you connect to your IOS devices normally, i.e. outside Ansible?

If yes, then I have no idea what's going on, but if not, get that working first before you try doing it with Ansible.

Off the cuff theory is that the devices do not permit telnet connections...

Regards, K.


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/60dd5a69-5a23-4c53-9bcf-08e5e8df6b44%40googlegroups.com.


--

Karl Auer { manager, systems support }
P: 1300 759 975
E: ka...@2pisoftware.com
2pisoftware.com

GPG/PGP : DF6A 43E5 FB9D D884 C6CA CD7F 5278 212D E80F C107
Previous: 301B 1F4E 624D AD99 242C 7A68 EC24 7113 E854 4A4E

Zaldy B

unread,
Apr 13, 2020, 3:51:28 AM4/13/20
to Ansible Project
Hi Karl,

yes, I can connect to the device from my ansible server using telnet.  I can also connect to the device using my putty (outside of ansible) using telnet.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.

Zaldy B

unread,
Apr 13, 2020, 3:58:39 AM4/13/20
to Ansible Project
I am getting this error:

FAILED! => {"changed": true, "msg": "Telnet action failed: telnet connection closed", "output": []}



On Monday, April 13, 2020 at 3:07:25 AM UTC-4, Zaldy B wrote:

Karl Auer

unread,
Apr 13, 2020, 4:05:53 AM4/13/20
to ansible-project
Unless you have some specific reason for wanting to use telnet, the obvious workaround is to use ssh instead....

Regards, K.


To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/77abad3c-b5ad-45c5-a2e2-d5e8331f73b6%40googlegroups.com.

Zaldy B

unread,
Apr 13, 2020, 4:14:38 AM4/13/20
to Ansible Project
Hi Karl,

Unfortunately, those devices that we have are old and uses telnet :)  

But other devices which are SSH enabled are being automated by ansible 

Srinivas Naram

unread,
Apr 13, 2020, 4:27:20 AM4/13/20
to ansible...@googlegroups.com
Some time back just to test telnet module, I tried telnet for devices which had ssh as well as telnet access. However I was not successful and gave up. If you get this working, kindly reply with the solution.

Thanks
Srinivas. 

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6c9852f6-30a6-4326-b29a-d2d354a947f8%40googlegroups.com.

Zaldy B

unread,
Apr 13, 2020, 4:37:13 AM4/13/20
to Ansible Project
Hi Srinivas,

Sure! I will update you.

This is just weird, I tried it on GNS3 and it is working. but on the prod itself, it is not. 

playbook is just straight forward:


---
- name: Telnet do show version for IOS
  hosts: Cisco_Telnet
  gather_facts: false
  connection: local

  tasks:
    - name: show version
      telnet:
        user: "{{ username }}"
        password: "{{ password }}"
        login_prompt: "Username:"
        prompts:
          - "[>|#]"
        command:
          - terminal length 0
          - show version


hostfile:

[Cisco_Telnet]
cisco_device    host=192.168.1.1   username=cisco password=cisco

Zaldy B

unread,
Apr 13, 2020, 10:28:59 AM4/13/20
to Ansible Project
Gettign this logs:

host_list declined parsing /etc/ansible/TEMPLATES/Cisco_Telnet as it did not pass it's verify_file() method
Skipping due to inventory source not existing or not being readable by the current user

Kai Stian Olstad

unread,
Apr 16, 2020, 2:32:52 AM4/16/20
to ansible...@googlegroups.com
On Mon, Apr 13, 2020 at 01:37:13AM -0700, Zaldy B wrote:
> playbook is just straight forward:
>
>
> ---
> - name: Telnet do show version for IOS
> hosts: Cisco_Telnet
> gather_facts: false
> connection: local
>
> tasks:
> - name: show version
> telnet:
> user: "{{ username }}"
> password: "{{ password }}"
> login_prompt: "Username:"
> prompts:
> - "[>|#]"
> command:
> - terminal length 0
> - show version
>
>
> hostfile:
>
> [Cisco_Telnet]
> cisco_device host=192.168.1.1 username=cisco password=cisco

This looks like a playbook just copied from documentation.
https://docs.ansible.com/ansible/latest/modules/telnet_module.html

Your task is missing host: default is the variable remote_addr according to the
documentation. So you need to provide host: or sett the correct variable.

You also need to tailor the prompt for you environment, it should be a list of
all prompt, you only have one prompt that is literally checking for [>|#] I
doubt you prompt looks like that.

If you can't figure this out yourself you need to provide the complete output
of telnet including telnet itself and the exit of the telnet.

--
Kai Stian Olstad

Zaldy B

unread,
Apr 16, 2020, 10:37:09 AM4/16/20
to Ansible Project
Hi Kai,

Thank you very much for replaying on my issue. I know that it should be straight forward, and I just copy it on the module

I am still getting the failure message even though I changed the hosts to


[Cisco_Telnet]
10.197.48.240


Tasks:

- name: Telnet do show version for IOS
  hosts: 10.197.48.240
  gather_facts: false
  connection: local

  tasks:
    - name: show version
      telnet:
        user: ansible
        password: Inf1n1TY
        login_prompt: "Username:"
        prompts:
          - "[#]"
        command:
          - terminal length 0
          - show version


Here is the error:

PLAY [Telnet do show version for IOS] ***************************************************************************************************************************************************************************************************************************************************************************************

TASK [show version] *********************************************************************************************************************************************************************************************************************************************************************************************************
fatal: [10.197.48.240]: FAILED! => {"changed": true, "msg": "Telnet action failed: telnet connection closed", "output": []}




Here is when i do the -vvv:

Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/TEMPLATES/Cisco_IOS as it did not pass it's verify_file() method

Brian Coca

unread,
Apr 21, 2020, 1:04:54 AM4/21/20
to Ansible Project
for telnet use 5 v's (-vvvvv) , 3 won't show anything about the task.


--
----------
Brian Coca

Zaldy B

unread,
Apr 22, 2020, 11:45:30 PM4/22/20
to Ansible Project
HI Brian,

Thank you for the reply. 

I did the 5v's as you mentioned, and dont know why it is saying that the hosts does not match. 

TEMPLATES]# cp IOS_telnet.yaml /etc/ansible/
[root@spm6637 TEMPLATES]# ansible-playbook -i Cisco_Telnet IOS_telnet.yaml
 [WARNING]: Unable to parse /etc/ansible/TEMPLATES/Cisco_Telnet as an inventory source
 [WARNING]: No inventory was parsed, only implicit localhost is available
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
 [WARNING]: Could not match supplied host pattern, ignoring: Cisco_Telnet

PLAY [Telnet do show version for IOS] ***********************************************************************************************************************
skipping: no hosts matched

PLAY RECAP **************************************************************************************************************************************************


I tried pinging it, and it was successful.

TEMPLATES]# ansible Cisco_Telnet -m ping
d2c2e-be-ag249-o | SUCCESS => {
    "changed": false, 
    "ping": "pong"


TEMPLATES]# ansible --list-host  Cisco_Telnet
  hosts (1):
    d2c2e-be-ag249-o

Zaldy B

unread,
Apr 22, 2020, 11:50:48 PM4/22/20
to Ansible Project
I can also see my inventory:

TEMPLATES]# ansible all --list-hosts
  hosts (1):
    d2c2e-be-ag249-o

Zaldy B

unread,
Apr 22, 2020, 11:52:24 PM4/22/20
to Ansible Project
Here is my cfg file:

ansible]# cat ansible.cfg
[defaults]
# Use local hosts file
inventory = /etc/ansible/hosts

# Disable SSH key host checking (RSA fingerprints)
host_key_checking = False

# Do not create .retry files on job failures
retry_files_enabled = False

# Do not gather facts
gathering = explicit

#Python Interpreter for Ansible 2.8 onwards
interpreter_python = /usr/bin/python3

Werner Flamme

unread,
Apr 23, 2020, 1:06:12 AM4/23/20
to ansible...@googlegroups.com
Zaldy B schrieb am 23.04.20 um 05:45:
> HI Brian,
>
> Thank you for the reply.
>
> I did the 5v's as you mentioned, and dont know why it is saying that the
> hosts does not match.
>
> TEMPLATES]# cp IOS_telnet.yaml /etc/ansible/
> [root@spm6637 TEMPLATES]# ansible-playbook -i Cisco_Telnet IOS_telnet.yaml

Zaldy,

-i is not to be followed by a hostname the playbook will be excuted on,
but by an inventory list (either a file name or a host list). You have
to specify the hosts file here, at least that is what the first WARNING
is about

> [WARNING]: Unable to parse /etc/ansible/TEMPLATES/Cisco_Telnet as an
> inventory source

The rest is a follow-up error: since the mentioned inventory list has
not been found, there is no 'all' host group and no host other than
'localhost' at all.

> [WARNING]: No inventory was parsed, only implicit localhost is available
> [WARNING]: provided hosts list is empty, only localhost is available. Note
> that the implicit localhost does not match 'all'
> [WARNING]: Could not match supplied host pattern, ignoring: Cisco_Telnet

My proposal: you should skip the "-i Cisco_Telnet" part of the
commandline and instead put the hostname inside the playbook.

>
> PLAY [Telnet do show version for IOS]
> ***********************************************************************************************************************
> skipping: no hosts matched
>
> PLAY RECAP
> **************************************************************************************************************************************************
>
>
> I tried pinging it, and it was successful.
>
> TEMPLATES]# ansible Cisco_Telnet -m ping
> d2c2e-be-ag249-o | SUCCESS => {
> "changed": false,
> "ping": "pong"
>
>
> TEMPLATES]# ansible --list-host Cisco_Telnet
> hosts (1):
> d2c2e-be-ag249-o
>
>
>
> On Tuesday, April 21, 2020 at 1:04:54 AM UTC-4, Brian Coca wrote:
>>
>> for telnet use 5 v's (-vvvvv) , 3 won't show anything about the task.
>>
>>
>> --
>> ----------
>> Brian Coca
>>
>>
>


--


Reply all
Reply to author
Forward
0 new messages