Add the singlePlacementGroup in the virtual machine scale set module (#58320)

This commit is contained in:
smile37773 2019-07-06 06:14:14 +08:00 committed by Zim Kalinowski
parent 0c992d5ae4
commit 8ff97edd1a
2 changed files with 36 additions and 2 deletions

View file

@ -209,6 +209,12 @@ options:
type: bool type: bool
default: True default: True
version_added: "2.8" version_added: "2.8"
single_placement_group:
description:
- When true this limits the scale set to a single placement group, of max size 100 virtual machines.
type: bool
default: True
version_added: "2.9"
zones: zones:
description: description:
- A list of Availability Zones for your virtual machine scale set. - A list of Availability Zones for your virtual machine scale set.
@ -273,6 +279,21 @@ EXAMPLES = '''
managed_disk_type: Standard_LRS managed_disk_type: Standard_LRS
image: customimage001 image: customimage001
- name: Create a VMSS with over 100 instances
azure_rm_virtualmachinescaleset:
resource_group: myResourceGroup
name: testvmss
vm_size: Standard_DS1_v2
capacity: 120
single_placement_group: False
virtual_network_name: testvnet
upgrade_policy: Manual
subnet_name: testsubnet
admin_username: adminUser
admin_password: password01
managed_disk_type: Standard_LRS
image: customimage001
- name: Create a VMSS with a custom image from a particular resource group - name: Create a VMSS with a custom image from a particular resource group
azure_rm_virtualmachinescaleset: azure_rm_virtualmachinescaleset:
resource_group: myResourceGroup resource_group: myResourceGroup
@ -436,6 +457,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
enable_accelerated_networking=dict(type='bool'), enable_accelerated_networking=dict(type='bool'),
security_group=dict(type='raw', aliases=['security_group_name']), security_group=dict(type='raw', aliases=['security_group_name']),
overprovision=dict(type='bool', default=True), overprovision=dict(type='bool', default=True),
single_placement_group=dict(type='bool', default=True),
zones=dict(type='list'), zones=dict(type='list'),
custom_data=dict(type='str') custom_data=dict(type='str')
) )
@ -468,6 +490,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
self.enable_accelerated_networking = None self.enable_accelerated_networking = None
self.security_group = None self.security_group = None
self.overprovision = None self.overprovision = None
self.single_placement_group = None
self.zones = None self.zones = None
self.custom_data = None self.custom_data = None
@ -571,8 +594,13 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
image_reference = self.get_custom_image_reference( image_reference = self.get_custom_image_reference(
self.image.get('name'), self.image.get('name'),
self.image.get('resource_group')) self.image.get('resource_group'))
elif self.image.get('id'):
try:
image_reference = self.compute_models.ImageReference(id=self.image['id'])
except Exception as exc:
self.fail("id Error: Cannot get image from the reference id - {0}".format(self.image['id']))
else: else:
self.fail("parameter error: expecting image to contain [publisher, offer, sku, version] or [name, resource_group]") self.fail("parameter error: expecting image to contain [publisher, offer, sku, version], [name, resource_group] or [id]")
elif self.image and isinstance(self.image, str): elif self.image and isinstance(self.image, str):
custom_image = True custom_image = True
image_reference = self.get_custom_image_reference(self.image) image_reference = self.get_custom_image_reference(self.image)
@ -649,6 +677,10 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
differences.append('overprovision') differences.append('overprovision')
changed = True changed = True
if bool(self.single_placement_group) != bool(vmss_dict['properties']['singlePlacementGroup']):
differences.append('single_placement_group')
changed = True
vmss_dict['zones'] = [int(i) for i in vmss_dict['zones']] if 'zones' in vmss_dict and vmss_dict['zones'] else None vmss_dict['zones'] = [int(i) for i in vmss_dict['zones']] if 'zones' in vmss_dict and vmss_dict['zones'] else None
if self.zones != vmss_dict['zones']: if self.zones != vmss_dict['zones']:
self.log("CHANGED: virtual machine scale sets {0} zones".format(self.name)) self.log("CHANGED: virtual machine scale sets {0} zones".format(self.name))
@ -739,6 +771,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
vmss_resource = self.compute_models.VirtualMachineScaleSet( vmss_resource = self.compute_models.VirtualMachineScaleSet(
location=self.location, location=self.location,
overprovision=self.overprovision, overprovision=self.overprovision,
single_placement_group=self.single_placement_group,
tags=self.tags, tags=self.tags,
upgrade_policy=self.compute_models.UpgradePolicy( upgrade_policy=self.compute_models.UpgradePolicy(
mode=self.upgrade_policy mode=self.upgrade_policy
@ -836,6 +869,7 @@ class AzureRMVirtualMachineScaleSet(AzureRMModuleBase):
vmss_resource.virtual_machine_profile.storage_profile.os_disk.caching = self.os_disk_caching vmss_resource.virtual_machine_profile.storage_profile.os_disk.caching = self.os_disk_caching
vmss_resource.sku.capacity = self.capacity vmss_resource.sku.capacity = self.capacity
vmss_resource.overprovision = self.overprovision vmss_resource.overprovision = self.overprovision
vmss_resource.single_placement_group = self.single_placement_group
if support_lb_change: if support_lb_change:
if self.load_balancer: if self.load_balancer:

View file

@ -584,7 +584,7 @@
image: image:
offer: UbuntuServer offer: UbuntuServer
register: fail_invalid_image_dict register: fail_invalid_image_dict
failed_when: 'fail_invalid_image_dict.msg != "parameter error: expecting image to contain [publisher, offer, sku, version] or [name, resource_group]"' failed_when: 'fail_invalid_image_dict.msg != "parameter error: expecting image to contain [publisher, offer, sku, version], [name, resource_group] or [id]"'
- name: assert error thrown with invalid image type - name: assert error thrown with invalid image type
azure_rm_virtualmachinescaleset: azure_rm_virtualmachinescaleset: