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: