Skip to content

Commit

Permalink
Add create_option to disk definitions (ansible#62357)
Browse files Browse the repository at this point in the history
Add create_option parameter to disk definitions to control whether disks
are created from the base image or are new disks being added to the VMs.
Currently, custom images with data disks defined in the image cannot be
used to launch VMs unless data disk definitions are excluded.  This
prevents the data disks from being modified/extended (like selecting a
different SKU or making the data disks bigger).  Exposing this option
allows VMSS VMs to be created with base images that have data disks
while extending their definitions.

Addresses ansible#61804
  • Loading branch information
sputnik13 authored Feb 20, 2020
1 parent 36def8b commit 23995fe
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/ansible/modules/cloud/azure/azure_rm_virtualmachinescaleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
- ReadWrite
default: ReadOnly
version_added: "2.4"
create_option:
description:
- Specify whether disk should be created Empty or FromImage. This is required to allow custom
images with data disks to be used.
choices:
- Empty
- FromImage
version_added: "2.10"
virtual_network_resource_group:
description:
- When creating a virtual machine, if a specific virtual network from another resource group should be
Expand Down Expand Up @@ -345,6 +353,26 @@
managed_disk_type: Standard_LRS
image: customimage001
- name: Create a VMSS with a custom image and override data disk
azure_rm_virtualmachinescaleset:
resource_group: myResourceGroup
name: testvmss
vm_size: Standard_DS1_v2
capacity: 2
virtual_network_name: testvnet
upgrade_policy: Manual
subnet_name: testsubnet
admin_username: adminUser
admin_password: password01
managed_disk_type: Standard_LRS
image: customimage001
data_disks:
- lun: 0
disk_size_gb: 64
caching: ReadWrite
managed_disk_type: Standard_LRS
create_option: FromImage
- name: Create a VMSS with over 100 instances
azure_rm_virtualmachinescaleset:
resource_group: myResourceGroup
Expand Down Expand Up @@ -963,7 +991,7 @@ def exec_module(self, **kwargs):
data_disks.append(self.compute_models.VirtualMachineScaleSetDataDisk(
lun=data_disk.get('lun', None),
caching=data_disk.get('caching', None),
create_option=self.compute_models.DiskCreateOptionTypes.empty,
create_option=data_disk.get('create_option', self.compute_models.DiskCreateOptionTypes.empty),
disk_size_gb=data_disk.get('disk_size_gb', None),
managed_disk=data_disk_managed_disk,
))
Expand Down Expand Up @@ -1020,7 +1048,7 @@ def exec_module(self, **kwargs):
data_disks.append(self.compute_models.VirtualMachineScaleSetDataDisk(
lun=data_disk['lun'],
caching=data_disk['caching'],
create_option=self.compute_models.DiskCreateOptionTypes.empty,
create_option=data_disk.get('create_option', self.compute_models.DiskCreateOptionTypes.empty),
disk_size_gb=data_disk['disk_size_gb'],
managed_disk=self.compute_models.VirtualMachineScaleSetManagedDiskParameters(
storage_account_type=data_disk.get('managed_disk_type', None)
Expand Down

0 comments on commit 23995fe

Please sign in to comment.