diff --git a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py index 454876f4850..aa54f5544cf 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py @@ -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 ) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk_facts.py b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk_facts.py index 9eda39e46d5..95abcea47d8 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk_facts.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk_facts.py @@ -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""" diff --git a/test/integration/targets/azure_rm_managed_disk/tasks/main.yml b/test/integration/targets/azure_rm_managed_disk/tasks/main.yml index 8bc424a39c4..6de0d3611fe 100644 --- a/test/integration/targets/azure_rm_managed_disk/tasks/main.yml +++ b/test/integration/targets/azure_rm_managed_disk/tasks/main.yml @@ -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 }}"