ansible - getting operational structured data from cumulus switch

  • 1
  • Question
  • Updated 3 weeks ago
Hi all,

I noticed that Cumulus Switch has a built-in JSON formatting in the NCLU 'net show' command but how to use it using ansible to get an operational structured data? And also I tried using the 'nclu' Network Module for example below;

- nclu:
     commands: show interface eth0 json

But it did not return anything, maybe I just miss something there. but then when I use an ansible 'command' module for example below.

- command: net show interface eth0 json

It did return something but not a structured one.

Thanks in advance.
Photo of Reynold


  • 80 Points 75 badge 2x thumb

Posted 4 weeks ago

  • 1
Photo of Nick Mitchell

Nick Mitchell, Employee

  • 544 Points 500 badge 2x thumb
Hi Reynold,

It looks like I was able to get structured output using the command module. With the following playbook contents:
- hosts: spine02
  become: true
    - command: net show interface eth0 json
      register: output
    - debug: msg='{{ output.stdout }}'
I get the following output when running the playbook:
nmitchell@prophecy ~/git/topology_converter $ ap test.yml
PLAY [spine02] **************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************
Monday 26 February 2018  15:56:23 -0500 (0:00:00.026)       0:00:00.026 ******* 
ok: [spine02]
TASK [command] **************************************************************************************************************************
Monday 26 February 2018  15:56:24 -0500 (0:00:00.759)       0:00:00.785 ******* 
changed: [spine02]
TASK [debug] ****************************************************************************************************************************
Monday 26 February 2018  15:56:24 -0500 (0:00:00.307)       0:00:01.092 ******* 
ok: [spine02] => {
    "msg": {
        "connector_type": "Unknown", 
        "iface_obj": {
            "asic": null, 
            "counters": null, 
            "description": "", 
            "dhcp_enabled": true, 
            "ip_address": {
                "allentries": [
            "ip_neighbors": {
                "ipv4": [
                "ipv6": []
            "lacp": {
                "bypass": "", 
                "partner_mac": "", 
                "rate": "", 
                "sys_priority": ""
            "lldp": null, 
            "mac": "52:54:00:bd:2a:ae", 
            "members": {}, 
            "min_links": "", 
            "mtu": 1500, 
            "native_vlan": null, 
            "vlan": null, 
            "vlan_filtering": false
        "linkstate": "UP", 
        "mode": "Mgmt", 
        "speed": "1G", 
        "summary": "IP:"
PLAY RECAP ******************************************************************************************************************************
spine02                    : ok=3    changed=1    unreachable=0    failed=0   
Monday 26 February 2018  15:56:24 -0500 (0:00:00.035)       0:00:01.128 ******* 
Gathering Facts --------------------------------------------------------- 0.76s
command ----------------------------------------------------------------- 0.31s
debug ------------------------------------------------------------------- 0.04s
Is this the type of structured output you were looking for?
Photo of Eric Pulvino

Eric Pulvino, Official Rep

  • 3,798 Points 3k badge 2x thumb
I also go one step further to convert the JSON data coming back into a native Ansible variable that can be parsed and used to inform other tasks, the example below applies to the output from the decode_syseeprom command however it could be used for NCLU JSON outputs as well.

- name: Collect System Parameters in JSON
  shell: /usr/cumulus/bin/decode-syseeprom -j
  register: decode_syseeprom_json
  changed_when: False
- name: Convert JSON into Ansible native variable type
    decode_syseeprom: "{{decode_syseeprom_json.stdout | from_json }}"
  changed_when: False
Photo of Reynold


  • 80 Points 75 badge 2x thumb
Hi Nick,

Thanks for the reply and that is the structured output I was expecting during my testing. It was my bad, I did not receive same output as yours because of my stdout_callback which is set to actionable. Thanks again.