From bc80087cca61474956cbf49a421ed984b538b74e Mon Sep 17 00:00:00 2001 From: Yuwei Zhou Date: Thu, 6 Dec 2018 02:40:19 +0800 Subject: [PATCH] azure_rm_image: fix creation of image with data disks (#49394) (#49518) * azure_rm_image: fix creation of image with data disks (#49394) (cherry picked from commit 79c0e30c5a8e16b8583861a86b1455833ea6158e) * Create 49394_azure_image.yml --- changelogs/fragments/49394_azure_image.yml | 3 +++ .../modules/cloud/azure/azure_rm_image.py | 6 +++--- .../targets/azure_rm_image/tasks/main.yml | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/49394_azure_image.yml diff --git a/changelogs/fragments/49394_azure_image.yml b/changelogs/fragments/49394_azure_image.yml new file mode 100644 index 00000000000..1a0c3cf62b5 --- /dev/null +++ b/changelogs/fragments/49394_azure_image.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- fix azure_rm_image module use positional parameter (https://github.com/ansible/ansible/pull/49394) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_image.py b/lib/ansible/modules/cloud/azure/azure_rm_image.py index deb9b5dc15a..9c2feb6e132 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_image.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_image.py @@ -247,9 +247,9 @@ class AzureRMImage(AzureRMModuleBase): def create_data_disk(self, lun, source): blob_uri, disk, snapshot = self.resolve_storage_source(source) if blob_uri or disk or snapshot: - snapshot_resource = self.compute_models.SubResource(snapshot) if snapshot else None - managed_disk = self.compute_models.SubResource(disk) if disk else None - return self.compute_models.ImageDataDisk(lun, + snapshot_resource = self.compute_models.SubResource(id=snapshot) if snapshot else None + managed_disk = self.compute_models.SubResource(id=disk) if disk else None + return self.compute_models.ImageDataDisk(lun=lun, blob_uri=blob_uri, snapshot=snapshot_resource, managed_disk=managed_disk) diff --git a/test/integration/targets/azure_rm_image/tasks/main.yml b/test/integration/targets/azure_rm_image/tasks/main.yml index cd1c1d0d60c..614a693fad6 100644 --- a/test/integration/targets/azure_rm_image/tasks/main.yml +++ b/test/integration/targets/azure_rm_image/tasks/main.yml @@ -6,6 +6,7 @@ public_ip_name: "pip{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" security_group_name: "sg{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" blob_name: "blob{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" + empty_disk_name: "emptydisk{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" - name: Create storage account azure_rm_storageaccount: @@ -78,12 +79,22 @@ name: "{{ vm_name }}" vm_size: Standard_A0 +- name: Create new empty managed disk + azure_rm_managed_disk: + resource_group: "{{ resource_group }}" + name: "{{ empty_disk_name }}" + storage_account_type: "Standard_LRS" + disk_size_gb: 1 + register: emptydisk + - name: Create an image from VM (check mode) azure_rm_image: resource_group: "{{ resource_group }}" source: "https://{{ storage_name }}.blob.core.windows.net/{{ storage_container_name }}/{{ blob_name }}.vhd" name: testimage001 os_type: Linux + data_disk_sources: + - "{{ empty_disk_name }}" check_mode: yes register: output @@ -150,6 +161,12 @@ that: - not output.changed +- name: Delete empty disk + azure_rm_managed_disk: + resource_group: "{{ resource_group }}" + name: "{{ empty_disk_name }}" + state: absent + - name: Delete VM azure_rm_virtualmachine: resource_group: "{{ resource_group }}"