Ansible with network equipment (Comware 5 switch)

715 views
Skip to first unread message

Ugo Bellavance

unread,
Aug 9, 2019, 9:41:17 AM8/9/19
to Ansible Project
Hi,

I'm new to Ansible.  I wanted to manage my network devices with Ansible so I did this:
  • Found this documentation: http://patg.net/ansible,comware,switches/2014/10/16/ansible-comware/
  • Created an account on my switch, tested that it can login via SSH (password only, haven't configured an SSH key yet)
  • Installed ansible (from EPEL), on RHEL7 (see below for version details)
  • Cloned the comware 5.2 module in $HOME/.ansible/plugins/modules (git clone https://github.com/CaptTofu/comware_5_2.git)
  • Cloned the Github project to get playbook examples (git clone https://github.com/CaptTofu/comware_5_2_playbooks.git)
  • Created an inventory file (see below)
  • Created a playbook (see below)
  • Ran ansible-playbook (ansible-playbook -i switch1 -u ansiblehpe --ask-pass playbook1.yml)
  • Got this error message
    • fatal: [192.168.xx.xx]: FAILED! => {"msg": "module (setup) is missing interpreter line"}
  • So I though I would add the shebang with the path of the python interpeter on my server running ansible in the setup.py file
    • Got these errors:
      •  [WARNING]: Unhandled error in Python interpreter discovery for host 192.168.99.41: Failed to connect to the host via ssh:
      •  [WARNING]: sftp transfer mechanism failed on [192.168.99.41]. Use ANSIBLE_DEBUG=1 to see detailed information
      •  [WARNING]: scp transfer mechanism failed on [192.168.99.41]. Use ANSIBLE_DEBUG=1 to see detailed information
  • I realized ansible wanted to discover where could python be on the remote target, but there isn't any interpreter there, it's a network switch...
  • I set an empty shebang in the setup.py file and got this error
    • An exception occurred during task execution. To see the full traceback, use -vvv. The error was: IndexError: list index out of range
      fatal: [192.168.99.41]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}
How do I tell ansible that there isn't any interpreter on the target?

Any help would be appreciated.
Thanks in advance.

$ ansible --version
ansible 2.8.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ubellavance/.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
  python version = 2.7.5 (default, Jun 11 2019, 12:19:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

Inventory file:

[switch1]
192.168.xx.xx

[switch1:vars]
switch_host=192.168.xx.xx
switch_user=xxxxxxxx
switch_password=xxxxxxxx


Playbook:

- hosts: switch1
  tasks:
  - name: gather facts from switch
    comware_5_2:
      gather_facts=true
      host={{ switch_host }}
      username={{ switch_user }}
      password={{ switch_password }}

Kai Stian Olstad

unread,
Aug 10, 2019, 12:17:57 PM8/10/19
to ansible...@googlegroups.com
On 09.08.2019 15:41, Ugo Bellavance wrote:
> - fatal: [192.168.xx.xx]: FAILED! => {"msg": "module (setup) is
> missing interpreter line"}

Default the first thing Ansible does is to gather facts, this is the
setup module.
Since you switch don't have Python this will not work an need to be
disables by setting gather_facts: no on the play.


--
Kai Stian Olstad

Ugo Bellavance

unread,
Aug 11, 2019, 7:44:32 PM8/11/19
to ansible...@googlegroups.com
According to the blog post, it is supposed to work, but Ansible is supposed to use switch commands to get facts, not python. Is there a way to tell Ansible not to try to discover python on the remote target?

Thanks,

--
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/427918591a464ca26e69cee128a2398a%40olstad.com.

Jonathan Lozada De La Matta

unread,
Aug 12, 2019, 1:54:23 AM8/12/19
to ansible...@googlegroups.com
can you provie the playbook file

Jonathan Lozada De La Matta on mobile
 

From: ansible...@googlegroups.com on behalf of Ugo Bellavance <ug...@lubik.ca>
Sent: Monday, August 12, 2019 12:44 AM
To: ansible...@googlegroups.com
Subject: Re: [ansible-project] Ansible with network equipment (Comware 5 switch)
 

Ganesh Nalawade

unread,
Aug 12, 2019, 3:30:46 AM8/12/19
to Ansible Project

The module seems to use paramiko_ssh to connect to the remote host.
Try changing the inventory entry as below since the module is expected to run on the control node.

[switch1]
192.168.xx.xx ansible_connection=local

OR

[switch1]
localhost

Also, this seems to be a very old module and not using the Ansible persistent connection framework.
You can add Ansible cliconf and terminal plugins for the network os to make it work with connection=network_cli
After adding the required plugins you use cli_command and cli_config modules to manage the remote host.

Shane Carnahan

unread,
Aug 12, 2019, 8:35:31 AM8/12/19
to Ansible Project
Specify the connect fo the host as below:
ansible_connection: network_cli

Ugo Bellavance

unread,
Aug 12, 2019, 11:46:03 PM8/12/19
to Ansible Project


On Monday, August 12, 2019 at 1:54:23 AM UTC-4, Jonathan Lozada De La Matta wrote:
can you provie the playbook file

The playbook is in my original post.
Reply all
Reply to author
Forward
0 new messages