From 16fa49a8940efff3566ed8a93add09ff22cc9b3f Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Thu, 20 Sep 2018 07:51:37 +0800 Subject: [PATCH] adding os disk name (#45126) * adding os disk name * fixed test --- .../cloud/azure/azure_rm_virtualmachine.py | 15 ++++++++++++++- .../tasks/virtualmachine.yml | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py index 470f941db23..ccb2efc2ac2 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine.py @@ -144,6 +144,10 @@ options: - Standard_LRS - Premium_LRS version_added: "2.4" + os_disk_name: + description: + - OS disk name + version_added: "2.8" os_disk_caching: description: - Type of OS disk caching. @@ -706,6 +710,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase): default='ReadOnly'), os_disk_size_gb=dict(type='int'), managed_disk_type=dict(type='str', choices=['Standard_LRS', 'Premium_LRS']), + os_disk_name=dict(type='str'), os_type=dict(type='str', choices=['Linux', 'Windows'], default='Linux'), public_ip_allocation_method=dict(type='str', choices=['Dynamic', 'Static', 'Disabled'], default='Static', aliases=['public_ip_allocation']), @@ -743,6 +748,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase): self.os_disk_caching = None self.os_disk_size_gb = None self.managed_disk_type = None + self.os_disk_name = None self.network_interface_names = None self.remove_on_absent = set() self.tags = None @@ -894,6 +900,13 @@ class AzureRMVirtualMachine(AzureRMModuleBase): changed = True vm_dict['properties']['storageProfile']['osDisk']['caching'] = self.os_disk_caching + if self.os_disk_name and \ + self.os_disk_name != vm_dict['properties']['storageProfile']['osDisk']['name']: + self.log('CHANGED: virtual machine {0} - OS disk name'.format(self.name)) + differences.append('OS Disk name') + changed = True + vm_dict['properties']['storageProfile']['osDisk']['name'] = self.os_disk_name + if self.os_disk_size_gb and \ self.os_disk_size_gb != vm_dict['properties']['storageProfile']['osDisk']['diskSizeGB']: self.log('CHANGED: virtual machine {0} - OS disk size '.format(self.name)) @@ -1038,7 +1051,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase): ), storage_profile=self.compute_models.StorageProfile( os_disk=self.compute_models.OSDisk( - name=self.storage_blob_name, + name=self.os_disk_name if self.os_disk_name else self.storage_blob_name, vhd=vhd, managed_disk=managed_disk, create_option=self.compute_models.DiskCreateOptionTypes.from_image, diff --git a/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml b/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml index aac665d9758..f0f6fc9a940 100644 --- a/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml +++ b/test/integration/targets/azure_rm_virtualmachine/tasks/virtualmachine.yml @@ -323,6 +323,7 @@ short_hostname: testvm os_type: Linux os_disk_size_gb: 64 + os_disk_name: testosdiskxx network_interfaces: "{{ niclist }}" availability_set: "{{ abs_name2 }}" image: @@ -334,6 +335,7 @@ - assert: that: - azure_vm.properties.availabilitySet.id + - azure_vm.properties.storageProfile.osDisk.name == 'testosdiskxx' - name: Retrieve vms facts (filtering by name) azure_rm_virtualmachine_facts: