From 9f4d46d8aff7cc41f975dd3603dbff29a2872ba4 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Fri, 23 Sep 2022 18:13:13 +0800 Subject: [PATCH 1/2] Fix Ansible azure_rm_deployment module returns error but deployment in Azure was successful --- plugins/modules/azure_rm_deployment.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_deployment.py b/plugins/modules/azure_rm_deployment.py index c8b293b0c..07d43dbe1 100644 --- a/plugins/modules/azure_rm_deployment.py +++ b/plugins/modules/azure_rm_deployment.py @@ -681,9 +681,18 @@ def _get_ip_dict(self, ip): return ip_dict def _nic_to_public_ips_instance(self, nics): + nic_list = [] + for nic in nics: + resp = None + try: + resp = self.network_client.network_interfaces.get(self.resource_group, nic['dep'].resource_name) + except ResourceNotFoundError: + pass + if resp is not None: + nic_list.append(resp) + return [self.network_client.public_ip_addresses.get(public_ip_id.split('/')[4], public_ip_id.split('/')[-1]) - for nic_obj in (self.network_client.network_interfaces.get(self.resource_group, - nic['dep'].resource_name) for nic in nics) + for nic_obj in nic_list for public_ip_id in [ip_conf_instance.public_ip_address.id for ip_conf_instance in nic_obj.ip_configurations if ip_conf_instance.public_ip_address]] From 365cccb31b1df130f1c2370ffb6cdca9ec17e92b Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Fri, 23 Sep 2022 20:08:53 +0800 Subject: [PATCH 2/2] fix sanity error --- plugins/modules/azure_rm_deployment.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/azure_rm_deployment.py b/plugins/modules/azure_rm_deployment.py index 07d43dbe1..1807f4d05 100644 --- a/plugins/modules/azure_rm_deployment.py +++ b/plugins/modules/azure_rm_deployment.py @@ -411,6 +411,7 @@ try: from itertools import chain from azure.common.exceptions import CloudError + from azure.core.exceptions import ResourceNotFoundError from azure.mgmt.resource.resources import ResourceManagementClient from azure.mgmt.network import NetworkManagementClient