#I have been having a hard time with this Creating a variable that is a list of items and a :

1 messages · Page 1 of 1 (latest)

muted pollen
#
  • name: Gathering DR Cluster Volume Information
    netapp.ontap.na_ontap_rest_info:
    gather_subset:
    - storage/volumes
    hostname: "{{ dr_cluster }}"
    username: "{{ username }}"
    password: "{{ password }}"
    https: true
    validate_certs: false
    fields:
    - svm.name
    register: drvolumes

    parameters:

    -svm_name: dr_vserver

    tags: dr
    when: dr_vserver !="none"

    • name: build new variable
      set_fact:
      drvolume1: "{{ drvolumes['ontap_info']['storage/volumes']['records'] }}"

    • name: Display variable dr
      set_fact:
      drvolume2: "{{ item.svm.name }}:{{ item.name }}"
      with_items: "{{ drvolume1 }}"

    • name: Display variable pr
      debug:
      var: drvolume2

The part I am having trouble with is at the end. I want drvolume2 to contain a list of all the svmnames:itemnames It only assigns the last one. I have looked on the internet to have it build out but nothing has worked as of yet.

#

I have been having a hard time with this Creating a variable that is a list of items and a :

tired coyote
muted pollen
#

Thank you, for my purposes. I had to construct a variable that contained both the svm and the volume as a single entry to check for their existence as a pair. Ironically the solution was simple, I set a variable in the vars section for the new variable . prvolume2: []. Then I used that variable in the loop and iterated it onto itself. Rundown of just this variable and solution is below

vars:

#

vars:
prvolume2: []

- name: Gathering PR Cluster Volume Information
  netapp.ontap.na_ontap_rest_info:
    gather_subset:
      - storage/volumes
    hostname: "{{ pr_cluster }}"
    username: "{{ username }}"
    password: "{{ password }}"
    https: true
    validate_certs: false
    fields:
      - svm.name
  register: prvolumes
tags: always
  • name: Set search array for PR
    set_fact:
    prvolume2: "{{ item.name }}:{{ item.svm.name }} {{prvolume2}}"
    with_items: "{{ prvolumes['ontap_info']['storage/volumes']['records'] }}"
    loop_control:
    label: " PR List "
#

I Used a loop control to cut down the verbosity alot. This gave me a new list I could check against

#
  • name: Check if PR Volume Exist
    assert:
    that:
    - "'{{ vol + '_pr:' + pr_vserver }}' not in prvolume2"
    fail_msg: "{{ vol }}_pr already exists"
    quiet: yes
    tags: pr
#

So a bit of a step around. THe info module used to have a field that notated the svm:volumename that no longer exists so this was the next best thing and only pulls minimal info from the endpoint.

tired coyote
#

Do you know what that vaule was called in ZAPI

muted pollen
#

let me look into that. I went into the rest api and looked at the model of the data but didn't find a direct replacement.

#

Our script just checked the old info module which used to return a value that had svm:volume format. Both are in the rest module but are not directly connected.

muted pollen
#

I think as I do more I will definitely find better ways. Right now I am retrofitting old scripts trying to keep them intact with the new modules where needed.