disk fact should return create_option value (#42398)

This commit is contained in:
Yuwei Zhou 2018-07-10 16:16:28 +08:00 committed by Yunge Zhu
parent 593f484d77
commit e9bf3c70e6
3 changed files with 21 additions and 20 deletions

View file

@ -146,16 +146,17 @@ except ImportError:
def managed_disk_to_dict(managed_disk):
os_type = None
if managed_disk.os_type:
os_type = managed_disk.os_type.name
create_data = managed_disk.creation_data
return dict(
id=managed_disk.id,
name=managed_disk.name,
location=managed_disk.location,
tags=managed_disk.tags,
create_option=create_data.create_option.value.lower(),
source_uri=create_data.source_uri,
source_resource_uri=create_data.source_resource_id,
disk_size_gb=managed_disk.disk_size_gb,
os_type=os_type,
os_type=managed_disk.os_type.value if managed_disk.os_type else None,
storage_account_type=managed_disk.sku.name.value,
managed_by=managed_disk.managed_by
)

View file

@ -79,27 +79,12 @@ from ansible.module_utils.azure_rm_common import AzureRMModuleBase
try:
from msrestazure.azure_exceptions import CloudError
from ansible.modules.cloud.azure.azure_rm_managed_disk import managed_disk_to_dict
except:
# handled in azure_rm_common
pass
def managed_disk_to_dict(managed_disk):
os_type = None
if managed_disk.os_type:
os_type = managed_disk.os_type.name
return dict(
id=managed_disk.id,
name=managed_disk.name,
location=managed_disk.location,
tags=managed_disk.tags,
disk_size_gb=managed_disk.disk_size_gb,
os_type=os_type,
storage_account_type=managed_disk.sku.name.value,
managed_by=managed_disk.managed_by
)
class AzureRMManagedDiskFacts(AzureRMModuleBase):
"""Utility class to get managed disk facts"""

View file

@ -1,6 +1,7 @@
- name: Prepare random number
set_fact:
rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}"
parameter: {}
run_once: yes
- name: Clearing (if) previous disks were created
@ -174,6 +175,7 @@
azure_rm_managed_disk_facts:
resource_group: "{{ resource_group }}"
name: "md{{ rpfx }}1"
register: fact
- assert:
that:
@ -187,6 +189,19 @@
that:
- "azure_managed_disk | length > 0"
- set_fact:
parameter: "{{parameter |combine({item.key: item.value})}}"
when: "{{item.key not in ['id', 'changed'] and item.value != None}}"
with_dict: "{{ fact.ansible_facts.azure_managed_disk[0] }}"
- name: Create disk with facts return value
azure_rm_managed_disk: "{{ parameter | combine({'resource_group': resource_group}) }}"
register: output
- assert:
that:
- not output.changed
- name: Create virtual network
azure_rm_virtualnetwork:
resource_group: "{{ resource_group }}"