From f85cd0b0c2f163545fbb6916d9865e8cf1d5fa35 Mon Sep 17 00:00:00 2001 From: Zim Kalinowski Date: Tue, 19 Feb 2019 00:47:35 +0800 Subject: [PATCH] Backport/2.7/49704 (#52467) * backport image crash fix * adding changelog fragment --- .../fragments/49704-fix-vm-facts-crash.yaml | 2 ++ .../azure/azure_rm_virtualmachine_facts.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/49704-fix-vm-facts-crash.yaml diff --git a/changelogs/fragments/49704-fix-vm-facts-crash.yaml b/changelogs/fragments/49704-fix-vm-facts-crash.yaml new file mode 100644 index 00000000000..d3954eaa90a --- /dev/null +++ b/changelogs/fragments/49704-fix-vm-facts-crash.yaml @@ -0,0 +1,2 @@ +bugfixes: +- azure_rm_virtualmachine_facts - fix crash when vm created from custom image diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py index b2e112ddc77..85695cd79c4 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py @@ -299,12 +299,17 @@ class AzureRMVirtualMachineFacts(AzureRMModuleBase): new_result['admin_username'] = os_profile.get('adminUsername') image = result['properties']['storageProfile'].get('imageReference') if image is not None: - new_result['image'] = { - 'publisher': image['publisher'], - 'sku': image['sku'], - 'offer': image['offer'], - 'version': image['version'] - } + if image.get('publisher', None) is not None: + new_result['image'] = { + 'publisher': image['publisher'], + 'sku': image['sku'], + 'offer': image['offer'], + 'version': image['version'] + } + else: + new_result['image'] = { + 'id': image.get('id', None) + } vhd = result['properties']['storageProfile']['osDisk'].get('vhd') if vhd is not None: