#Aggregate Loop

1 messages · Page 1 of 1 (latest)

steel relic
#

Hello all,

I query the aggregates as follows and then want to store the percentage level per aggregate in a variable:

  • name: Aggregate Informationen für den Primary Cluster abfragen
    netapp.ontap.na_ontap_rest_info:
    gather_subset:
    - aggregate_info
    fields:
    - 'space'
    https: true
    use_rest: always
    validate_certs: false
    hostname: "{{ primaryCluster }}"
    username: "{{ username }}"
    password: "{{ password }}"
    register: primaryAggregateInfo

However, with the new Rest module I still do not manage to loop the aggregates. Does anyone have an idea how this works?

  • name: Aggregate Liste für den Primary Cluster erstellen
    set_fact:
    primaryAggregates: "{{ item.value.name }}"
    with_items: "{{ primaryAggregateInfo | dict2items }}"

  • debug:
    msg: "{{ primaryAggregates }}"

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'name'\n\nThe error appears to be in 'createSVM.yml': line 156, 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: Aggregate Liste für den Primary Cluster erstellen\n ^ here\n"}

little parrot
#

Do a debug output of your variable to get a better understanding of the structure. It should be something like this (untested):

primaryAggregateInfo.ontap_info['storage/aggregates'].records

split ridge
#

^agreed. If you can paste the debug output of primaryAggregateInfo it would help us visualize the data structure you're working with

steel relic
little parrot
#

To stay in you example, you have to loop over "records". The square brackets in your output indicate a list.
` - name: Get aggr
netapp.ontap.na_ontap_rest_info:
gather_subset: aggregate_info
fields: space
register: primaryAggregateInfo

  • name: set list
    set_fact:
    primaryAggregates: "{{ item.name }}"
    loop: "{{ primaryAggregateInfo.ontap_info['storage/aggregates'].records }}"

  • debug:
    var: primaryAggregates`

To get the task done you mentioned you need a little bit more. Getting multiple attributes from one variable into another is always ugly in Ansible. If you can avoid it, just use the gathered info object directly. If it is unavoidable I suggest to use json_query to extract the properties you need.
- name: set list set_fact: primaryAggregates: "{{ primaryAggregateInfo.ontap_info['storage/aggregates'].records |json_query(aggrspace_query) }}" vars: aggrspace_query: "[].{name: name, used: space.block_storage.physical_used_percent}"

steel relic
#

Thank you very much for the help. The example works and brings exactly the result I wanted.