Software Development Kit (SDK) and API Discussions

na_ontap_volume: fails to delete volume when state is set to absent


na_ontap_volume faisl to delete a volume on a filer when using state: absent



i created a new 1GB test volume using the ontap CLI , to test the deletion process. ... like so ....


emdccn0006::> vol create -vserver emdccn0005v55dr -volume testvol_12345 -aggregate emdccn0006c02_aggr2 -size 1g -state online


emdccn0006::> vol show testvol_12345
Vserver Volume Aggregate State Type Size Available Used%
--------- ------------ ------------ ---------- ---- ---------- ---------- -----
emdccn0005v55dr testvol_12345 emdccn0006c02_aggr2 online RW 1GB 972.6MB 5%


emdccn0006::> version
NetApp Release 9.1P16: Wed Nov 14 19:51:52 UTC 2018



so filer = version 9.1P16 


the ansible doco for na_ontap_volume shows the following example ...

- name: Volume Delete
    state: absent
    name: ansibleVolume12
    aggregate_name: ansible_aggr
    vserver: ansibleVServer
    hostname: "{{ netapp_hostname }}"
    username: "{{ netapp_username }}"
    password: "{{ netapp_password }}"


so following on from this .....

i then created a yml file to delete the volume using ansible like so ...

$ cat delete-dr-volume.yml

- hosts: localhost
gather_facts: false

name: "Ansible Storage Delete ..."

- name: "Delete Volume : testvol_12345 , if it exists ..."
state: absent
name: testvol_12345
aggregate_name: emdccn0006c02_aggr2
vserver: emdccn0005v55dr
username: admin
password: XXXXX


(cut and paste didnt quite align , noted above )

d629924@vm010$ pip show netapp-lib
Name: netapp-lib
Version: 2019.12.20
Summary: netapp-lib is required for Ansible deployments to interact with NetApp storage systems.
Home-page: UNKNOWN
Author: NetApp, Inc.
License: Proprietary::NetApp
Location: /usr/local/lib/python3.6/site-packages
Requires: lxml, xmltodict


note : i'm using netapp-lib = Version: 2019.12.20


i get this error when running the playbook ...


$ ansible-playbook ./pb-delete/delete-dr-volume.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Ansible Storage Delete ...] *******************************************************************************************************************

TASK [Delete Volume : testvol_12345 , if it exists ...] ********************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'No element by given name volume-comp-aggr-attributes.'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/home/d629924/.ansible/tmp/ansible-tmp-1610682403.28-220492199842676/\", line 102, in <module>\n _ansiballz_main()\n File \"/home/d629924/.ansible/tmp/ansible-tmp-1610682403.28-220492199842676/\", line 94, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/d629924/.ansible/tmp/ansible-tmp-1610682403.28-220492199842676/\", line 40, in invoke_module\n runpy.run_module(mod_name='', init_globals=None, run_name='__main__', alter_sys=True)\n File \"/usr/lib64/python2.7/\", line 176, in run_module\n fname, loader, pkg_name)\n File \"/usr/lib64/python2.7/\", line 82, in _run_module_code\n mod_name, mod_fname, mod_loader, pkg_name)\n File \"/usr/lib64/python2.7/\", line 72, in _run_code\n exec code in run_globals\n File \"/tmp/ansible_na_ontap_volume_payload_MN3wQK/\", line 1283, in <module>\n File \"/tmp/ansible_na_ontap_volume_payload_MN3wQK/\", line 1279, in main\n File \"/tmp/ansible_na_ontap_volume_payload_MN3wQK/\", line 1221, in apply\n File \"/tmp/ansible_na_ontap_volume_payload_MN3wQK/\", line 565, in get_volume\n File \"/usr/lib/python2.7/site-packages/netapp_lib/api/zapi/\", line 489, in __getitem__\n raise KeyError('No element by given name %s.' % key)\nKeyError: 'No element by given name volume-comp-aggr-attributes.'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

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



the specific error is : 


An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'No element by given name volume-comp-aggr-attributes.'


Can anyone assist me with my issue ? Not sure what i'm doing wrong, unless the fix is a netapp-lib upgrade ?


Regards Adrian







Hi Adrian,


The slack channels on  is the quickest place to get help on this.  

A few points about what's going on. 

1.  You might want to consider a ONTAP upgrade to 9.5+ 

2.  I don't think you need to specify the aggregate_name in the remove command

3. You might need to unmount the volume prior to deleting it.

4. ONTAP collections have replaced the syntax your currently using which would also address points 2 and 3 above there is a blog post on that addresses this topic. 


I hope this helps!





I'm facing the same issue with error "No element by given name volume-comp-aggr-attributes." when running a playbook with na_ontap_volume: onto ONTAP Release 9.1P9

This happens when run the playbook for the 2nd or more time.

Is this due to the lower ONTAP-release?

NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner