How to login to Avocent servers and run ansible playbooks on the Network devices which are connected serially

I have been redirected from git hub issue list to here. Could someone please take a look and suggest:

I am trying to work on a scenario in which I want to access Cisco and Juniper network devices and run my ansible network modules like get facts, get config, push config commands on them through ansible. The network devices are connected via console ports to an Avocent AS6000 server. So from a CentOS machine which is my ansible host machine, I want to login to the Avocent Server and then access the network devices using ansible playbooks. I am not sure how to go about it. Can anyone please guide me. I am new to this and sorry if i have posted in the wrong forum.
Please note: I am able to run playbooks directly through management port of the Network devices. This serial console route is a second way to access the devices and need to write playbooks in case the management IP goes down or is inaccessible.

COMPONENT NAME
Network Modules

ANSIBLE VERSION
ansible --version
ansible 2.3.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
`
OS / ENVIRONMENT
Centos7
Avocent Server ACS6000
Juniper EX2200

SUMMARY
Could someone please guide on how do I use ansible to login from my CentOS machine to an Avocent server and then navigate to different network devices that are connected serially on each port and run playbooks on it. Both CentOS and Avocent server is on the same network. I am able to ssh to the avocent device, but how do I access the network devices from it.

Manual steps to access:

  1. Login to avocent server via ssh through putty.
  2. Go to cli mode. by typing cli command
  3. Go to a particular folder which gives the port list of all the connected devices. The port number corresponds to each device connected serially to it

Also, here is the playbook to check ssh connectivity:

  • hosts: avocent
    gather_facts: no
    connection: local

    tasks:

    • name: Check SSH CONNECTIVITY
      tags: push
      wait_for: host={{ansible_host}} port=22 timeout=5

    • name: print results
      debug: var=result

``
ACTUAL RESULTS
ok: [avocentfirst] => {
“changed”: false,
“elapsed”: 0,
“invocation”: {
“module_args”: {
“active_connection_states”: [
“ESTABLISHED”,
“SYN_SENT”,
“SYN_RECV”,
“FIN_WAIT1”,
“FIN_WAIT2”,
“TIME_WAIT”
],
“connect_timeout”: 5,
“delay”: 0,
“exclude_hosts”: null,
“host”: “xx.xx.xx.xx”,
“path”: null,
“port”: 22,
“search_regex”: null,
“sleep”: 1,
“state”: “started”,
“timeout”: 5
}
},
“path”: null,
“port”: 22,
“search_regex”: null,
“state”: “started”
}

Below is the failure message when I try to acess the network device:
Failure message:

"msg": "unable to connect to xx.xx.xx.x..: ConnectError(host: xx.xx.xx.xx, msg: Unexpected session close\

Ansible does not support serial console connection.
However, there are other ways to bootstrap a working ssh connection to the network device and that can be managed by Ansible.

One possible way is you can use pyserial to write a script that connects to the network device over serial console connection and perform minimal configuration that enables Ansible to talk to Network device over ssh.

Regards,
Ganesh

Could you get this to work?

I am running into the same issue.

Thank you!