#How to validate a volume exists with na_ontap_rest_info?

1 messages · Page 1 of 1 (latest)

wise siren
#

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:

  1. Ensure volumes are online.
  2. Delete snapmirror relationships.
  3. 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
forest solstice
#

Because filer_pri_info['ontap_info']['storage/volumes']['records'] is a list you can't use it like this. You would have to address elements of the list like filer_pri_info['ontap_info']['storage/volumes']['records'][0]['name'] to get the first list element. Which doesn't help you much for what you try to achieve.

Check the documentation for select & map to filter lists for your desired elements.