Telnet to network devices

32 views
Skip to first unread message

Ashish Sagar

unread,
Mar 1, 2020, 5:26:43 AM3/1/20
to ansible...@googlegroups.com
Folks,

I am aware that native ansible doesn't  support telnet. Do we have any alternate to test playbooks while telnet to network devices  in lab environment ?

Thanks
Ashish

Claudia de Luna

unread,
Mar 1, 2020, 10:06:22 AM3/1/20
to Ansible Project
Hi Ashish,

Have you tried the Telnet module?

The docs actually include IOS examples:


Sample Playbook:

root@f23399314267:/ansible_local/cisco_ios# cat telnet.yml
---

- name: Telnet Example
  hosts: local_lab
  gather_facts: false
  connection: local
  ignore_errors: yes

  tasks:
    - name: run show commands
      telnet:
        user: cisco
        password: cisco
        login_prompt: "Username: "
        prompts:
          - "[>#]"
        command:
          - show ip int br

      register: output
    - name: Display output
      debug:
        var: output




Sample Output:

root@f23399314267:/ansible_local/cisco_ios# ansible-playbook -i hosts telnet.yml

PLAY [Telnet Example] *************************************************************************************************************

TASK [run show commands] **********************************************************************************************************
changed: [10.1.10.101]

TASK [Display output] *************************************************************************************************************
ok: [10.1.10.101] => {
    "output": {
        "changed": true,
        "failed": false,
        "output": [
            "show ip int br\r\nInterface                  IP-Address      OK? Method Status                Protocol\r\nEthernet0                  10.1.10.101     YES NVRAM  up                    up      \r\nLoopback0                  10.1.0.99       YES NVRAM  up                    up      \r\nSerial0                    unassigned      YES NVRAM  administratively down down    \r\nSerial1                    unassigned      YES NVRAM  administratively down down    \r\nTS-2509>"
        ]
    }
}

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

root@f23399314267:/ansible_local/cisco_ios#


Reply all
Reply to author
Forward
0 new messages