ansible-collections / community.yang

Ansible Community Collection to support Yang in network devices.
GNU General Public License v3.0
10 stars 14 forks source link

community.yang.get not working on IOS-XRv #56

Open stevenca opened 3 years ago

stevenca commented 3 years ago
SUMMARY

community.yang.get not working on IOS-XRv, but ansible.netcommon.netconf_get works.

ISSUE TYPE
COMPONENT NAME

community.yang.get

ANSIBLE VERSION
$ ansible --version
ansible 2.10.7
  config file = /Users/stevenca/Workspaces/mdd/ansible.cfg
  configured module search path = ['/Users/stevenca/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/stevenca/Workspaces/mdd/venv-mdd/lib/python3.9/site-packages/ansible
  executable location = /Users/stevenca/Workspaces/mdd/venv-mdd/bin/ansible
  python version = 3.9.0 (default, Dec  6 2020, 18:02:34) [Clang 12.0.0 (clang-1200.0.32.27)]
CONFIGURATION
$ ansible-config dump --only-changed
HOST_KEY_CHECKING(/Users/stevenca/Workspaces/mdd/ansible.cfg) = False
PERSISTENT_COMMAND_TIMEOUT(/Users/stevenca/Workspaces/mdd/ansible.cfg) = 60
PERSISTENT_CONNECT_TIMEOUT(/Users/stevenca/Workspaces/mdd/ansible.cfg) = 60
OS / ENVIRONMENT

Cisco IOS XR Software, Version 6.3.1

STEPS TO REPRODUCE

Run the example below against an IOS-XRv node. Not sure if the problem manifests on other IOS-XR nodes.

- hosts: all
  connection: ansible.netcommon.netconf
  gather_facts: no
  vars:
    host_var_dir: "inventory/arch1/host_vars/{{ inventory_hostname }}"
    yang_files_dir: "{{ playbook_dir }}/yang_files/{{ inventory_hostname }}"
    models:
  tasks:
    - name: Fetch the yang models
      community.yang.fetch:
        name: all
        dir: "{{ yang_files_dir }}"

    - name: Get running configuration and state data
      ansible.netcommon.netconf_get:
        display: json
        filter: <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"></interface-configurations>
      connection: ansible.netcommon.netconf
      register: netconf_get

    - debug:
        var: netconf_get.output

    - name: get interface configuration in json/xml format
      community.yang.get:
        filter: <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"></interface-configurations>
        file: "{{ yang_files_dir }}/Cisco-IOS-XR-ifmgr-cfg.yang"
        search_path: "{{ yang_files_dir }}"
      connection: ansible.netcommon.netconf
      register: yang_get

    - debug:
        var: yang_get
EXPECTED RESULTS

I would expect community.yang.get to work and give similar results to ansible.netcommon.netconf_get

ACTUAL RESULTS

community.yang.get fails

$ ansible-playbook get-netconf.yml -i iosxr.yml

PLAY [all] ****************************************************************************************************************************************************************************************************************************************************************************************************

TASK [Fetch the yang models] **********************************************************************************************************************************************************************************************************************************************************************************
changed: [iosxr]

TASK [Get running configuration and state data] ***************************************************************************************************************************************************************************************************************************************************************
ok: [iosxr]

TASK [debug] **************************************************************************************************************************************************************************************************************************************************************************************************
ok: [iosxr] => {
    "netconf_get.output": {
        "data": {
            "interface-configurations": {
                "interface-configuration": [
                    {
                        "active": "act",
                        "interface-name": "MgmtEth0/0/CPU0/0",
                        "ipv4-network": {
                            "addresses": {
                                "dhcp": ""
                            }
                        }
                    },
                    {
                        "active": "act",
                        "interface-name": "GigabitEthernet0/0/0/0",
                        "shutdown": ""
                    },
                    {
                        "active": "act",
                        "interface-name": "GigabitEthernet0/0/0/1",
                        "shutdown": ""
                    },
                    {
                        "active": "act",
                        "interface-name": "GigabitEthernet0/0/0/2",
                        "shutdown": ""
                    }
                ]
            }
        }
    }
}

TASK [get interface configuration in json/xml format] *********************************************************************************************************************************************************************************************************************************************************
Aborting, bad element: ipv4-network
fatal: [iosxr]: FAILED! => {"changed": false, "msg": "Error while reading json document Expecting ',' delimiter: line 6 column 46 (char 168) from path /Users/stevenca/.ansible/tmp/xml2json/14b8983a-4dfc-4eb7-8a10-cfe7f0ff34a5/96e70992-9d95-4914-b43b-90f6dc570422.json"}

PLAY RECAP ****************************************************************************************************************************************************************************************************************************************************************************************************
iosxr                      : ok=3    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0