ansible-collections / ansible.netcommon

Ansible Network Collection for Common Code
GNU General Public License v3.0
144 stars 104 forks source link

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

Open crytectobi opened 11 months ago

crytectobi commented 11 months ago
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
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 commented 9 months ago

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.