cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4032
Views
6
Helpful
10
Replies

<bad-element>cli-config-data</bad-element>

kim
Level 1
Level 1

Hi everybody,

thank you for a great resource!

 

I'm attempting at configuring a CSR router (16.09.05) with netconf - however not with xml, rather with cli stuff. I'm getting this error message:

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101" xmlns:cpi="http://www.cisco.com/cpi_10/schema"><rpc-error>
<error-type>application</error-type>
<error-tag>unknown-element</error-tag>
<error-severity>error</error-severity>
<error-path>
    /rpc/edit-config/config
  </error-path><error-info><bad-element>cli-config-data</bad-element>
</error-info>
</rpc-error>
</rpc-reply>

The snippet i'm trying to send to the router is the following:

 

    <?xml version="1.0" encoding="UTF-8"?>
    <rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"  xmlns:cpi="http://www.cisco.com/cpi_10/schema">        
        <edit-config>     
            <target>         
                <running/>      
            </target>      
            <config>         
                <cli-config-data>
                    hostname test
                    interface loo1000
                    ip address 192.168.1.1 255.255.255.0
                <cli-config-data>
            </config>   
        </edit-config>
    </rpc> 

Just some garbage config to see if i could get it to work. I'm trying to get my head wrapped around the CPI name space but it is not working.

 

Has anyone had any success with this?

 

Thanks in advance.

/Kim

10 Replies 10

omz
VIP Alumni
VIP Alumni

Hi

I think .. should be ..

<cmd>hostname test</cmd>

 

omz
VIP Alumni
VIP Alumni

https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/cns/configuration/15-s/cns-15-s-book/cns-netconf.html#GUID-D925E60E-D1F6-42B3-BBF8-E51505CD5518

 

<cli-config-data>
 <cmd>hostname test</cmd>
 <cmd>interface fastEthernet0/1</cmd>
 <cmd>ip address 192.168.1.1 255.255.255.0</cmd>
</cli-config-data>

OR

<cli-config-data-block>
 hostname bob
 interface fastEthernet0/1
 ip address 192.168.1.1 255.255.255.0
</cli-config-data-block>

Hi guys :)

Thank you for helping out!

 

I went back and had a look at my code, your suggestions are right according to the namespace in the document you suggest.

 

This is the part of the namespace that i use:

Device# show netconf schema
New Name Space 'urn:ietf:params:xml:ns:netconf:base:1.0'
<VirtualRootTag> [0, 1] required
  <rpc> [0, 1] required
    <close-session> [0, 1] required
    <commit> [0, 1] required
      <confirmed> [0, 1] required
      <confirm-timeout> [0, 1] required
    <edit-config> [0, 1] required
      <target> 1 required
        <candidate> [0, 1] required
        <running> [0, 1] required
        <startup> [0, 1] required
        <url> [0, 1] required
      <default-operation> [0, 1] required
      <test-option> [0, 1] required
      <error-option> [0, 1] required
      <config> 1 required
        <cli-config-data> [0, 1] required
          <cmd> 1+ required
        <cli-config-data-block> [0, 1] required
        <xml-config-data> [0, 1] required
          <Device-Configuration> [0, 1] required
            <> any subtree is allowed

This is what my script sends to the CSR1000v (16.9.5):

 

    <?xml version="1.0" encoding="UTF-8"?>
    <rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">        
        <edit-config>     
            <target>         
                <running/>      
            </target>      
            <config>         
                <cli-config-data-block>
                    hostname test
                    interface loo1000
                    ip address 192.168.1.1 255.255.255.0
                <cli-config-data-block>
            </config>   
        </edit-config>
    </rpc>

But i still get the error message...:

 

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101" xmlns:cpi="http://www.cisco.com/cpi_10/schema"><rpc-error>
<error-type>application</error-type>
<error-tag>unknown-element</error-tag>
<error-severity>error</error-severity>
<error-path>
    /rpc/edit-config/config
  </error-path><error-info><bad-element>cli-config-data-block</bad-element>
</error-info>
</rpc-error>
</rpc-reply>

Can you guys help me figure out what is missing?

Thanks in advance.

 

Cheers

/Kim 

omz
VIP Alumni
VIP Alumni

Hi

Missing / in the closing tag .. try with putting / in </cli-config-data-block>

<cli-config-data-block>
    hostname test
    interface loo1000
    ip address 192.168.1.1 255.255.255.0
</cli-config-data-block>

 

omz
VIP Alumni
VIP Alumni

You can use an XML validator to validate your XML - 

https://www.liquid-technologies.com/online-xml-validator

Screenshot 2020-05-24 at 15.42.32.pngScreenshot 2020-05-24 at 15.43.20.png

Hey :)

Thanks... Typos! And thanks for the tip about the syntax checker.

However, i still get an error... cli-config-data and cli-config-data-block triggers a bad-element response. 

The elements should, from what i can find, be part of this namespace 

xmlns:cpi="http://www.cisco.com/cpi_10/schema"

But that throws an unknown namespace error. Does anyone have a working example for the CSR1000v on how to send config in cli format with the cli-config-data-block?

 

NOTE: I've done some additional testing - i have an 1100 router and a couple of CSR's in my lab. When ssh'ing to them the namespace mentioned above seems to be accepted. BUT the cli-config-data-block and cli-config-data throw an error - bad element. I've found some examples but none that actually work.

 

Any input appreciated!

 

Cheers and thanks :)

Best regards

/Kim

Chris Mason
Level 1
Level 1

Did you have any luck? I am suffering from the same issue in that I can't send CLI based configuration to an ISR running IOS-XE 16.9.6 (with "netconf-yang" enabled) - I keep on getting "<bad-element>config-text</bad-element>" when trying to use the "netconf_config" module with Ansible.

 

Ansible Playbook is fairly simple:

 

    - netconf_config:
        content: "build/{{ inventory_hostname }}.cfg"
        target: "running"
        format: "text"

I have tried defining the configuration in various different ways with different tags without any luck:

 

<cli-config-data-block>
  hostname bob
</cli-config-data-block>

Spent 5 hours so far trying to get Ansible to push config changes to an IOS-XE device using Ansible! Unfortunately "debug netconf-yang level debug" doesn't help at all

 

/Chris

Many hours later I think I have worked it out - posting here so hopefully no one else spends as much time as I did trying to get this to work. In IOS-XE you have the option to enable "netconf ssh" or "netconf-yang" - I made the mistake of enabling "netconf-yang" and then tried to use "cli-config-data-block" as I assumed it was valid as I saw it in "show netconf schema".

 

If you enable "netconf-yang" then it expects a valid YANG model, but "netconf ssh" enables legacy NETCONF support which uses the schema as output by "show netconf schema". Once you enable "netconf ssh" then the following can be sent to the device to update the configuration:

 

<?xml version='1.0' encoding='UTF-8'?>
<rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="100">
  <edit-config>
    <target>
      <running/>
    </target>
    <config>
      <cli-config-data-block>
        hostname test
      </cli-config-data-block>
    </config>
  </edit-config>
</rpc>

Now I just need to work out how to send multiline strings as the above doesn't seem to support the following syntax

menu test title $
this is a title
$

frbello
Cisco Employee
Cisco Employee

If anyone has still this issue with ncclient/ansible netconf_config module and IOS 17, the solution is to explicit declare the top level namespace. Some Tasks and labs about NETCONF in Devnet site still use the syntax of older ncclient versions. In my case, for edit-config rpc calls my working config has

'''
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<--YOUR PAYLOAD HERE-->
</config>
'''

For filtering

<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<-- YOUR FILTER SUBTREE HERE -->
</filter>
 
And for Ansible Config, this is the task config
 
name: Configure Interfaces with NETCONF module
tags: [api, netconf, routing, layer3]
netconf_config:
target: running
content: "{{ lookup('file', './config/{{inventory_hostname}}-ospf.xml') }}"
format: xml

opokharel
Level 1
Level 1

worked for me when i had a bad element error. Thanks @frbello !

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: