summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZim Kalinowski <zikalino@microsoft.com>2019-02-22 09:03:59 +0800
committerToshio Kuratomi <a.badger@gmail.com>2019-02-21 17:03:59 -0800
commitf80e9070a537475405221a98c468fea4ce2a66c9 (patch)
tree3374fedb24d75d1712e121f19c2ac882a4895ee0
parentec8c1cb34aa00bc940ffb8efd4b7ba5a3feb5ab2 (diff)
downloadansible-f80e9070a537475405221a98c468fea4ce2a66c9.tar.gz
Backport/2.7/52540 (#52545)
* fixed deallocated vm facts problem (#52540) (cherry picked from commit d6600b0ab69c76f4632c7a72bd71166fe085f5e3) * added changelog
-rw-r--r--changelogs/fragments/52540-fix-vm-facts-crashing-managed-disk.yaml2
-rw-r--r--lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py8
2 files changed, 6 insertions, 4 deletions
diff --git a/changelogs/fragments/52540-fix-vm-facts-crashing-managed-disk.yaml b/changelogs/fragments/52540-fix-vm-facts-crashing-managed-disk.yaml
new file mode 100644
index 0000000000..b1efdcfac6
--- /dev/null
+++ b/changelogs/fragments/52540-fix-vm-facts-crashing-managed-disk.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+- azure_rm_virtualmachine_facts - fixed crash related to attached managed disks (https://github.com/ansible/ansible/issues/52181)
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 85695cd79c..25390cde1e 100644
--- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py
+++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_facts.py
@@ -324,10 +324,10 @@ class AzureRMVirtualMachineFacts(AzureRMModuleBase):
disks = result['properties']['storageProfile']['dataDisks']
for disk_index in range(len(disks)):
new_result['data_disks'].append({
- 'lun': disks[disk_index]['lun'],
- 'disk_size_gb': disks[disk_index]['diskSizeGB'],
- 'managed_disk_type': disks[disk_index]['managedDisk']['storageAccountType'],
- 'caching': disks[disk_index]['caching']
+ 'lun': disks[disk_index].get('lun'),
+ 'disk_size_gb': disks[disk_index].get('diskSizeGB'),
+ 'managed_disk_type': disks[disk_index].get('managedDisk', {}).get('storageAccountType'),
+ 'caching': disks[disk_index].get('caching')
})
new_result['network_interface_names'] = []