Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible.netcommon.netconf_config delete not working and missing example in documentation #602

Open
crytectobi opened this issue Nov 17, 2023 · 1 comment
Assignees

Comments

@crytectobi
Copy link

SUMMARY

I tried to delete configuration from my IOS-XE switch with the ansible.netcommon.netconf_config module.
Pushing configuration is working fine, also commiting is working fine. But how do I delete specific configuration from the switch?
In this example I'm trying to delete the interface description:

    - name: Delete interface description
      ansible.netcommon.netconf_config:
        lock: "never"
        commit: false
        delete: true
        target: candidate
        format: xml
        get_filter: <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"><interface><GigabitEthernet><name>1/0/2</name></GigabitEthernet></interface></native>
        content: |
          <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
            <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
              <interface>
                <GigabitEthernet>
                  <name>1/0/2</name>
                  <description></description>
                </GigabitEthernet>
              </interface>
            </native>
          </config>

The results is:
"parameters are mutually exclusive: content|source_datastore|delete|confirm_commit"

So when delete and content are not mutual, how do I define what I want to be deleted?
I also tried this without the delete option:

    - name: Delete interface description
      ansible.netcommon.netconf_config:
        lock: "never"
        commit: false
        target: candidate
        format: xml
        get_filter: <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"><interface><GigabitEthernet><name>1/0/2</name></GigabitEthernet></interface></native>
        content: |
          <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
            <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
              <interface>
                <GigabitEthernet>
                  <name>1/0/2</name>
                  <description nc:operation="delete"></description>
                </GigabitEthernet>
              </interface>
            </native>
          </config>

The results is:
XML validation failed with error 'Namespace prefix nc for operation on description is not defined

And since there is no documentation example of the delete option, I don't know how to use this correctly.
Can someone enlighten me and maybe add this to the documentation, if this is not a bug?

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible.netcommon.netconf_config

ANSIBLE VERSION
ansible [core 2.16.0]
  config file = /home/tblachetta/cisco-ansible/ansible.cfg
  configured module search path = ['/home/tblachetta/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/tblachetta/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/tblachetta/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/tblachetta/.local/bin/ansible
  python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION

-->

Collection                    Version
----------------------------- -------
ansible.netcommon             5.3.0 
CONFIGURATION
CALLBACKS_ENABLED(/home/tblachetta/cisco-ansible/ansible.cfg) = ['profile_tasks']
CONFIG_FILE() = /home/tblachetta/cisco-ansible/ansible.cfg
DEFAULT_GATHERING(/home/tblachetta/cisco-ansible/ansible.cfg) = explicit
DEFAULT_LOG_PATH(/home/tblachetta/cisco-ansible/ansible.cfg) = /var/log/ansible.log
HOST_KEY_CHECKING(/home/tblachetta/cisco-ansible/ansible.cfg) = False
INTERPRETER_PYTHON(/home/tblachetta/cisco-ansible/ansible.cfg) = /usr/bin/python3
INVENTORY_ENABLED(/home/tblachetta/cisco-ansible/ansible.cfg) = ['host_list', 'yaml', 'constructed', 'netbox', 'auto', 'netbox.netbox.nb_inventory']
PARAMIKO_LOOK_FOR_KEYS(/home/tblachetta/cisco-ansible/ansible.cfg) = False
PERSISTENT_COMMAND_TIMEOUT(/home/tblachetta/cisco-ansible/ansible.cfg) = 600
PERSISTENT_CONNECT_TIMEOUT(/home/tblachetta/cisco-ansible/ansible.cfg) = 600
OS / ENVIRONMENT

Ansible is running on Ubuntu 22.04 WSL
Cisco Catalyst Switch 9200 IOS-XE 17.12.1

@frants4ever
Copy link

frants4ever commented Jan 18, 2024

One way that I've found we can delete some config with netconf and Ansible it's RPC. You should use other module and pre-built rpc edit-config. To delete description for interface Ansible task will look like this

tasks:
   - name: Delete description
     ansible.netcommon.netconf_rpc:
       rpc: edit-config
       xmlns: urn:ietf:params:xml:ns:netconf:base:1.0
       content: |
         <target>
           <running/>
         </target>
         <config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
           <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
             <interface>
               <GigabitEthernet>
                 <name>1/0/2</name>
                 <description nc:operation="remove">test</description>
               </GigabitEthernet>
             </interface>
           </native>
         </config> 

I tried it at another vendor than Cisco, but it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants