Search code examples
ansibletelnetcisco

Ansible telnet without username login


I need to connect to cisco devices with ansible telnet module (I can't enable SSH). In all the tutorial I found on the web, everyone is specifying a login username and a password for authenticating in telnet.

But my router doesn't have a username need, the auth prompt start directly with the mesage :

Password:

Here's my files :

inventory.yml :

[cisco]
test ip_address=xxx.yyy.zzz

[cisco:vars]
password=test
password_enable=test

plays/cisco.yml :

---

- hosts: cisco
  connection: local
  roles:
    - role: cisco-telnet

roles/cisco-telnet/tasks/main.yml :

---
- name: Telnet test
  telnet:
    host: "{{ ip_address }}"
    port: 23
    password_prompt: "Password:"
    password: "{{ password }}"
    prompts:
      - '[>|#]'
    command:
      - enable
      - "{{ password_enable }}"
      - show running-config

I got an error message everytime :

FAILED! => {
    "msg": "Unexpected failure during module execution.",
    "stdout": ""
}

How can I use telnet module without specifying a username ? Someone already did that ?


Solution

  • Studying the source code of the telnet module and reading the documentation I assume the follwing behaviour:

    If the password is empty then no password prompt is expected.

    It follows that you can use the login prompt for the password. Somewhat strange, so I guess the following code snippet should work:

    - name: Telnet test
      telnet:
        host: "{{ ip_address }}"
        port: 23
        login_prompt: "Password:"
        user: "{{ password }}"
        prompts:
          - '[>|#]'
        command:
          - enable
          - "{{ password_enable }}"
          - show running-config
    

    I can't test it because I do not have a telnet server anymore, you are 20 years late ;-)