#batch creation of volumes using loop

1 messages · Page 1 of 1 (latest)

final rapids
#

We've started using ansible in our environment for the purpose of creating volumes in our NetApp (FAS500f) and hopefully doing the same on our other NetApp. The question is, we sometimes have to create a high number of volumes, and we were hoping to use Ansible to batch create volumes using a loop. But when i create a loop, it tries to name the volume with each item in the loop.

below my yaml file:


  • hosts: localhost
    name: Create NFS Volumes for uas as VMware Datastore
    vars:
    hostname: x.x.x.x
    username: *********
    password: *********
    vol_name: "{{ item }}"
    item:
    - HM0_STCL02_N01_PER_FLEXVOL006
    - HM0_STCL02_N01_PER_FLEXVOL007
    - HM0_STCL02_N01_PER_FLEXVOL007
    #junction_name: /HM0_STCL02_N01_PER_FLEXVOL006
    collections:
    • netapp.ontap
      tasks:
    • name: Volume Create
      netapp.ontap.na_ontap_volume:
      state: present
      name: "{{ vol_name }}"
      is_infinite: False
      aggregate_name: HM0_STCL02_N01_SSD_CAP_1
      size: 6
      size_unit: tb
      user_id: 0
      group_id: 0
      space_guarantee: none
      tiering_policy: auto
      export_policy: EQ-Flexpod
      percent_snapshot_space: 16
      vserver: HM0_STCL02_N01_FLEX_NFS
      wait_for_completion: True
      #junction_path: "{{ junction_name }}"
      validate_certs: false
      use_rest: always
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"

the error message:

"msg": "Error creating volume ['HM0_STCL02_N01_PER_FLEXVOL006', 'HM0_STCL02_N01_PER_FLEXVOL007', 'HM0_STCL02_N01_PER_FLEXVOL007']: calling: storage/volumes: got {'message': 'Volume name: The first character must be a letter or underscore.', 'code': '917887', 'target': 'name'}."

}

Is it possible to loop volume creation? perhaps i'm using the wrong approach.

thank you.

final rapids
#

I have managed to fix the issue using with_items, would this be the best way or is loop preferred?

queen ginkgo
#

yes with_items works

final rapids
#

Thank you for your answer Mohan, the question is , how would i use loop , as in my example in my post i'm not getting the expected result. Instead of getting individual volumes it is trying to name my volume after each item in the loop as a whole.