diff --git a/lib/ansible/module_utils/azure_rm_common.py b/lib/ansible/module_utils/azure_rm_common.py index d27f4af5d5..515c585d4a 100644 --- a/lib/ansible/module_utils/azure_rm_common.py +++ b/lib/ansible/module_utils/azure_rm_common.py @@ -415,8 +415,8 @@ class AzureRMModuleBase(object): ''' try: return self.rm_client.resource_groups.get(resource_group) - except CloudError: - self.fail("Parameter error: resource group {0} not found".format(resource_group)) + except CloudError as cloud_error: + self.fail("Error retrieving resource group {0} - {1}".format(resource_group, cloud_error.message)) except Exception as exc: self.fail("Error retrieving resource group {0} - {1}".format(resource_group, str(exc))) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_acs.py b/lib/ansible/modules/cloud/azure/azure_rm_acs.py index 409fe0ce4f..79eadcc292 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_acs.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_acs.py @@ -523,10 +523,7 @@ class AzureRMContainerService(AzureRMModuleBase): results = dict() to_be_updated = False - try: - resource_group = self.get_resource_group(self.resource_group) - except CloudError: - self.fail('resource group {} not found'.format(self.resource_group)) + resource_group = self.get_resource_group(self.resource_group) if not self.location: self.location = resource_group.location diff --git a/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py b/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py index 6854e6c327..f2de8e6e9f 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_availabilityset.py @@ -203,10 +203,7 @@ class AzureRMAvailabilitySet(AzureRMModuleBase): response = None to_be_updated = False - try: - resource_group = self.get_resource_group(self.resource_group) - except CloudError: - self.fail('resource group {} not found'.format(self.resource_group)) + resource_group = self.get_resource_group(self.resource_group) if not self.location: self.location = resource_group.location diff --git a/lib/ansible/modules/cloud/azure/azure_rm_dnsrecordset.py b/lib/ansible/modules/cloud/azure/azure_rm_dnsrecordset.py index c530cad1d4..d8bd27b5dd 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_dnsrecordset.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_dnsrecordset.py @@ -279,8 +279,8 @@ class AzureRMRecordSet(AzureRMModuleBase): for key in self.module_arg_spec.keys(): setattr(self, key, kwargs[key]) - # get resource group and zone - resource_group = self.get_resource_group(self.resource_group) + # retrieve resource group to make sure it exists + self.get_resource_group(self.resource_group) zone = self.dns_client.zones.get(self.resource_group, self.zone_name) if not zone: self.fail('The zone {0} does not exist in the resource group {1}'.format(self.zone_name, self.resource_group)) diff --git a/lib/ansible/modules/cloud/azure/azure_rm_dnszone.py b/lib/ansible/modules/cloud/azure/azure_rm_dnszone.py index fbb59fe5d0..431935da35 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_dnszone.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_dnszone.py @@ -143,7 +143,7 @@ class AzureRMDNSZone(AzureRMModuleBase): self.results['check_mode'] = self.check_mode # retrieve resource group to make sure it exists - resource_group = self.get_resource_group(self.resource_group) + self.get_resource_group(self.resource_group) changed = False results = dict() diff --git a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py index 954fe8af3b..798886c20d 100755 --- a/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_loadbalancer.py @@ -324,11 +324,7 @@ class AzureRMLoadBalancer(AzureRMModuleBase): pip = None load_balancer_props = dict() - try: - resource_group = self.get_resource_group(self.resource_group) - except CloudError: - self.fail('resource group {} not found'.format(self.resource_group)) - + resource_group = self.get_resource_group(self.resource_group) if not self.location: self.location = resource_group.location load_balancer_props['location'] = self.location 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 a22a7f2c47..81213908cb 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_managed_disk.py @@ -234,12 +234,8 @@ class AzureRMManagedDisk(AzureRMModuleBase): results = dict() resource_group = None response = None - try: - resource_group = self.get_resource_group(self.resource_group) - except CloudError: - self.fail( - 'resource group {} not found' - .format(self.resource_group)) + + resource_group = self.get_resource_group(self.resource_group) if not self.location: self.location = resource_group.location if self.state == 'present': diff --git a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py index 214327f038..490d394c47 100644 --- a/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py +++ b/lib/ansible/modules/cloud/azure/azure_rm_virtualmachine_extension.py @@ -227,10 +227,7 @@ class AzureRMVMExtension(AzureRMModuleBase): response = None to_be_updated = False - try: - resource_group = self.get_resource_group(self.resource_group) - except CloudError: - self.fail('resource group {} not found'.format(self.resource_group)) + resource_group = self.get_resource_group(self.resource_group) if not self.location: self.location = resource_group.location