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 79c0e30c5a)

* Create 49394_azure_image.yml
This commit is contained in:
Yuwei Zhou 2018-12-06 02:40:19 +08:00 committed by Toshio Kuratomi
parent 9cc7f7bcf2
commit bc80087cca
3 changed files with 23 additions and 3 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- fix azure_rm_image module use positional parameter (https://github.com/ansible/ansible/pull/49394)

View file

@ -247,9 +247,9 @@ class AzureRMImage(AzureRMModuleBase):
def create_data_disk(self, lun, source): def create_data_disk(self, lun, source):
blob_uri, disk, snapshot = self.resolve_storage_source(source) blob_uri, disk, snapshot = self.resolve_storage_source(source)
if blob_uri or disk or snapshot: if blob_uri or disk or snapshot:
snapshot_resource = self.compute_models.SubResource(snapshot) if snapshot else None snapshot_resource = self.compute_models.SubResource(id=snapshot) if snapshot else None
managed_disk = self.compute_models.SubResource(disk) if disk else None managed_disk = self.compute_models.SubResource(id=disk) if disk else None
return self.compute_models.ImageDataDisk(lun, return self.compute_models.ImageDataDisk(lun=lun,
blob_uri=blob_uri, blob_uri=blob_uri,
snapshot=snapshot_resource, snapshot=snapshot_resource,
managed_disk=managed_disk) managed_disk=managed_disk)

View file

@ -6,6 +6,7 @@
public_ip_name: "pip{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" 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 }}" 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 }}" 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 - name: Create storage account
azure_rm_storageaccount: azure_rm_storageaccount:
@ -78,12 +79,22 @@
name: "{{ vm_name }}" name: "{{ vm_name }}"
vm_size: Standard_A0 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) - name: Create an image from VM (check mode)
azure_rm_image: azure_rm_image:
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"
source: "https://{{ storage_name }}.blob.core.windows.net/{{ storage_container_name }}/{{ blob_name }}.vhd" source: "https://{{ storage_name }}.blob.core.windows.net/{{ storage_container_name }}/{{ blob_name }}.vhd"
name: testimage001 name: testimage001
os_type: Linux os_type: Linux
data_disk_sources:
- "{{ empty_disk_name }}"
check_mode: yes check_mode: yes
register: output register: output
@ -150,6 +161,12 @@
that: that:
- not output.changed - not output.changed
- name: Delete empty disk
azure_rm_managed_disk:
resource_group: "{{ resource_group }}"
name: "{{ empty_disk_name }}"
state: absent
- name: Delete VM - name: Delete VM
azure_rm_virtualmachine: azure_rm_virtualmachine:
resource_group: "{{ resource_group }}" resource_group: "{{ resource_group }}"