From e31620e9db8562ebbd2bf567c67678f2b1e274e0 Mon Sep 17 00:00:00 2001 From: Yunge Zhu <37337818+yungezz@users.noreply.github.com> Date: Tue, 2 Apr 2019 04:27:39 +0800 Subject: [PATCH] Backport/2.7/53496: fix azure_rm.py not showing nic info for vmss #53496 (#54379) * fix azure_rm.py not showing nic info for vmss (#53496) * fix vmss nic * resolve comments (cherry picked from commit 710b05fae75aef07258eed0a0160a505e66f2b50) * add changelog --- .../53496-azure_rm_inventory_vmss_nic.yaml | 2 ++ lib/ansible/plugins/inventory/azure_rm.py | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/53496-azure_rm_inventory_vmss_nic.yaml diff --git a/changelogs/fragments/53496-azure_rm_inventory_vmss_nic.yaml b/changelogs/fragments/53496-azure_rm_inventory_vmss_nic.yaml new file mode 100644 index 0000000000..4a95745724 --- /dev/null +++ b/changelogs/fragments/53496-azure_rm_inventory_vmss_nic.yaml @@ -0,0 +1,2 @@ +bugfixes: +- azure_rm inventory plugin - fix no nic type in vmss nic. (https://github.com/ansible/ansible/pull/53496) diff --git a/lib/ansible/plugins/inventory/azure_rm.py b/lib/ansible/plugins/inventory/azure_rm.py index e79d5c7bd9..fe10d1f7fb 100644 --- a/lib/ansible/plugins/inventory/azure_rm.py +++ b/lib/ansible/plugins/inventory/azure_rm.py @@ -567,9 +567,8 @@ class AzureHost(object): for s in vm_instanceview_model.get('statuses', []) if self._powerstate_regex.match(s.get('code', ''))), 'unknown') def _on_nic_response(self, nic_model, is_primary=False): - if nic_model.get('type') == 'Microsoft.Network/networkInterfaces': - nic = AzureNic(nic_model=nic_model, inventory_client=self._inventory_client, is_primary=is_primary) - self.nics.append(nic) + nic = AzureNic(nic_model=nic_model, inventory_client=self._inventory_client, is_primary=is_primary) + self.nics.append(nic) class AzureNic(object): @@ -580,10 +579,11 @@ class AzureNic(object): self.public_ips = {} - for ipc in nic_model['properties']['ipConfigurations']: - pip = ipc['properties'].get('publicIPAddress') - if pip: - self._inventory_client._enqueue_get(url=pip['id'], api_version=self._inventory_client._network_api_version, handler=self._on_pip_response) + if nic_model.get('properties', {}).get('ipConfigurations'): + for ipc in nic_model['properties']['ipConfigurations']: + pip = ipc['properties'].get('publicIPAddress') + if pip: + self._inventory_client._enqueue_get(url=pip['id'], api_version=self._inventory_client._network_api_version, handler=self._on_pip_response) def _on_pip_response(self, pip_model): self.public_ips[pip_model['id']] = AzurePip(pip_model)