telnet issue

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:

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’

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.

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.

I am getting this error:

FAILED! => {“changed”: true, “msg”: “Telnet action failed: telnet connection closed”, “output”: }

Unless you have some specific reason for wanting to use telnet, the obvious workaround is to use ssh instead…

Regards, K.

Hi Karl,

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

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

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.

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:

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

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.

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

for telnet use 5 v's (-vvvvv) , 3 won't show anything about the task.

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

I can also see my inventory:

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

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

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.