ansible initialise multiple windows disks

Viewed 481

I am trying to initialize some disks that are getting added via vcenter. this is my code.

---
- hosts: all
#  vars:
#    disks:
#      - { disk_number: 0, drive_letter: 'D', new_label: 'temp'}
#      - { disk_number: 1, drive_letter: 'E', new_label: 'data'}
#      - { disk_number: 2, drive_letter: 'F', new_label: 'logs'}
#      - { disk_number: 3, drive_letter: 'G', new_label: 'misc'}
  tasks:
  - name: Initialize a disk
    community.windows.win_initialize_disk:
      disk_number: "{{ item.disk_number }}"
    loop: "{{ disks }}"
  - name : Create drive letter
    community.windows.win_partition:
      drive_letter: "{{ item.drive_letter }}"
      partition_size: -1
      disk_number: "{{ item.disk_number }}"
      read_only: no
    loop: "{{ disks }}"
  - name: Format the disk and assign the label
    community.windows.win_format:
      drive_letter: "{{ item.drive_letter }}"
      file_system: NTFS
      new_label: "{{ item.new_label }}"
      full: no
    loop: "{{ disks }}"

it works fine but it messes up the sequence. say I want D to be sqltemp and 60GB and E to be sqllogs and 100GB and 4 more disks like so, they get initialized but the labels and disk letters are all over the place. D might get assigned to 100GB and so on. how can I fix that? TIA

0 Answers
Related