#Nested Loop to Setup LIFs on SVMs

1 messages · Page 1 of 1 (latest)

jolly moss
#

I am trying to setup a playbook to create SVMs and all the underlying LIFs for each SVM. My thought is that I could put all the data for each SVM and each LIF into my inventory file and then do a nested loop to setup each SVM, and then setup each LIF within each SVM. But, I can see to wrap my head around the formatting that I need to use for the inventory entries and/or the nested loop. If anyone can tell me what I'm doing wrong here, or suggest a better way to do this, it would be much appreciated! I'm trying to keep all the information in a single inventory file so we can enter all the information in the cluster in one place, and do the minimal amount of editing to avoid data entry mistakes.

My message was too long, so check out the attached txt file for examples of inventory, playbook, and output.

rough flint
jolly moss
#

Thanks, @rough flint, that is essentially what I'm doing. I guess my struggle is how to layout the inventory file so that I can loop through multiple SVMs with multiple LIFs in each SVM. The NetApp role just has a with_items: "{{ vservers }}", so that's pretty simple. But, when it does with_items: "{{ lifs }}", how do I setup the inventory so that the various LIFs are associated with the SVM that the role is currently setting up? I guess a sample inventory file is what I'm looking for.

glossy bane
#

It's not hard to do with recent Ansible versions. subelements filter is your friend.
- debug: msg: "SVM: {{ item.0.name }}, LIFName: {{ item.1.name }}" loop: "{{ vservers.records |subelements('svm_interfaces') }}" loop_control: label: "{{ item.0.name }}"

jolly moss
#

Thanks, @glossy bane. What version of Ansible is required? We're still on 2.9.
I'll give that a shot though.

flint coral
#

Also, not sure how much flexibility you have with the var structure, but you could make your life a little easier using a structure like the following and then using the subelements filter like @glossy bane suggested:

  - name: vserver01
    svm_interfaces:
      - name: vserver01_data01
        ip: "10.10.10.13"
        home_node: "01"
        role: "data"
        port: "e0c"
      - name: vserver01_data02
        ip: "10.10.10.14"
        home_node: "02"
        role: "data"
        port: "e0d"
  - name: vserver02
    svm_interfaces:
      - name: vserver02_data01
        ip: "10.10.10.15"
        home_node: "01"
        role: "data"
        port: "e0c"
#

To loop through the vservers and svm_interfaces:

- debug:
    msg: "SVM: {{ item.0.name }}, LIFName: {{ item.1.name }}"
  loop: "{{ vservers | subelements('svm_interfaces') }}"
glossy bane
#

2.9 or 2.10 should work

fickle scarab
#

@jolly moss Just another thought on this: I banged my head on the table quite often when thinking about how to design a vars structures and then loop over them to get something done in ONTAP. I sticked to using, what ONTAP gives me to be honest.
https://library.netapp.com/ecmdocs/ECMLP2885799/html/index.html
It has the positive side effect, that I can theoretically read and store info from na_ontap_rest_info and re-use that with exactly the same playbooks for e.g. backing up/restoring/replicating an existing configuration.

Example: The REST API model separates SVMs and LIFs in two resources, where LIFs have an attribute indicating the parent SVM. This is the structure, that I am replicating in my inventory host_vars as well.

jolly moss
#

Thanks @glossy bane and @flint coral these examples worked perfectly! Wish I would have asked earlier!

jolly moss