diff --git a/changelogs/fragments/51781-fixing-managed-disk-facts.yaml b/changelogs/fragments/51781-fixing-managed-disk-facts.yaml new file mode 100644 index 0000000000..80b2940f6b --- /dev/null +++ b/changelogs/fragments/51781-fixing-managed-disk-facts.yaml @@ -0,0 +1,2 @@ +bugfixes: + - azure_rm_managed_disk_facts - added missing implementation of listing managed disks by resource group 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 6b2592a6f2..1664613024 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 @@ -175,7 +175,7 @@ class AzureRMManagedDiskFacts(AzureRMModuleBase): self.results['ansible_facts']['azure_managed_disk'] = ( self.get_item() if self.name - else self.list_items() + else (self.list_items_by_resource_group() if self.resource_group else self.list_items()) ) return self.results @@ -210,6 +210,19 @@ class AzureRMManagedDiskFacts(AzureRMModuleBase): results.append(managed_disk_to_dict(item)) return results + def list_items_by_resource_group(self): + """Get managed disks in a resource group""" + try: + response = self.compute_client.disks.list_by_resource_group(resource_group_name=self.resource_group) + except CloudError as exc: + self.fail('Failed to list items by resource group - {}'.format(str(exc))) + + results = [] + for item in response: + if self.has_tags(item.tags, self.tags): + results.append(managed_disk_to_dict(item)) + return results + def main(): """Main module execution code path"""