'Adding new disks based on user input during provisioning

I'm provisioning instances from GCP using ansible, below task works without any issues but if I need to add more disks, I have add the below mentioned list item into the task every time:

           - auto_delete: true
             boot: false
             interface: NVME
             type: SCRATCH
             initialize_params:
                     disk_type: local-ssd

Provisioning play:

- hosts: localhost
  vars_prompt:
    - name: disks
      private: no
      prompt: No. of Hard drives to be added
  tasks:
    - name: create a instance
      gcp_compute_instance:
        state: present
        name: "{{ vm_name }}"
        machine_type: "{{ machine_type }}"
        disks:
          - auto_delete: true
            boot: true
            source: "{{ disk }}"
          - auto_delete: true
            boot: false
            interface: NVME
            type: SCRATCH
            initialize_params:
              disk_type: local-ssd
#####How to add a loop or when statement to repeat the Disk addition based on the user input#####
        network_interfaces:
          - network: "{{ network }}"
        zone: "{{ zone }}"
        project: "{{ gcp_project }}"
        auth_kind: "{{ gcp_cred_kind }}"
        service_account_file: "{{ gcp_cred_file }}"
        scopes:
          - https://www.googleapis.com/auth/compute

I'm trying to add a vars_prompt to ask user the no. of HDDs to be added to the instances based on that need to repeat the disk lists. Do we have any options with until or loop.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source