Hey all,
How can I validate that a volume exists as a conditional?
Scenario: I need to delete a local snapmirror and a remote snapmirror volume that were created by Commvault and are no longer needed.
Basic steps:
- Ensure volumes are online.
- Delete snapmirror relationships.
- Delete volumes.
Problem is, if one of the volumes doesn't exist for some reason, the na_ontap_volume tries to create the volume, which is the last thing I need. The thing that saved it from creating the volume was that I hadn't specified an aggregate for the creation. So, using na_ontap_info and later na_ontap_rest_info, I tried to use a when statement to only run the online command if the volume exists. I'm having trouble getting the conditional to evaluate.
I am far from a JSON and ansible expert. See attached for full code & run error - hopefully (This is my first time posting on Discord)
The task with when statement:
na_ontap_volume:
name: "{{ item }}"
is_online: true
vserver: myvserver
<<: *loginPri
with_items:
- "{{ primary_vol }}"
- "{{ mirror_vol }}"
when:
- item in filer_pri_info['ontap_info']['storage/volumes']['records']['name']```
The error:
> TASK [Ensure primary volume is online] *************************************************************************************
> fatal: [localhost]: FAILED! => {"msg": "The conditional check 'item in filer_pri_info['ontap_info']['storage/volumes']['records']['name']' failed. The error was: error while evaluating conditional (item in filer_pri_info['ontap_info']['storage/volumes']['records']['name']): 'list object' has no attribute 'name'\n\nThe error appears to be in '/net_home/myuser/.ansible/netapp-snapmirror-vol-delete-test.yml': line 45, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Ensure primary volume is online\n ^ here\n"}
TIA, rm-f