#Ansible Automation Platform w/ exec env and ansible collection for netapp.

1 messages · Page 1 of 1 (latest)

frosty iris
#

Hi,
I've posted a couple of times before trying netapp.ontap v21.xx to v22.xx getting the notorious "KeyError: 'volume'"
I'm running this code to delete snapshots.

--- play ---
- name: delete SnapShot
netapp.ontap.na_ontap_snapshot:
https: true
validate_certs: false
state: absent
snapshot: "MegaAccDB_Snap.*"
volume: "db_mega_acc"
vserver: "my-svm"
username: '{{ lookup("env", "ANSIBLE_NET_USERNAME") }}'
password: '{{ lookup("env", "ANSIBLE_NET_PASSWORD") }}'
hostname: mystorage.com
--- end ---

Yesterday I upgraded to 22.3.0 and this problem is now gone but another culprit is causing it to fail. Please view the attached file.
Any hints are greatly appreciated! thank you.

#

Please reply here or DM me if you need any additional information.

nova kestrel
#

having * in snapshot name is the problem, module expecting one record but multiple records are returned

uneven zealot
#

I found a workaround getting snapshots with na_ontap_rest_info and then loop through a list for delete

nova kestrel
#

yes, this will fetch snapshot list and using loops on snapshot will modify all snapshots or we can delete all.

`- name: Gather snapshot with regex
  na_ontap_rest_info:
    gather_subset:
      - storage/volumes/snapshots
    parameters:
      name: policy-vserver*
    owning_resource:
      volume_name: db_mega_acc
      svm_name: my-svm
  register: result

- debug: var=result

- name: create snapshot list
  set_fact:
    snapshot_list: "{{ snapshot_list|default([]) + [item.name] }}"
  loop: "{{ result['ontap_info']['storage/volumes/snapshots']['records'] }}"

- debug: var=snapshot_list

- name: modify SnapShot
  na_ontap_snapshot:
    https: true
    validate_certs: false
    state: present
    snapshot: "{{ item }}"
    volume: "db_mega_acc"
    vserver: "my-svm"
  loop: "{{ snapshot_list }}"`
frosty iris
#

Please excuse my n00b questions. I've used the code above and it executes but the list is empty, no snapshots. I assume this is because the code is utilising the rest functionality (my code wasn't).
If so I need to get that working.

#

And again.

#

Thank you for the time and effort.

frosty iris
#

Got it working!

#

Super Excellent!

#

You guys rule!

#

Thank you!