From 3efedacadffa13172d4c4dc27782d059d5291fde Mon Sep 17 00:00:00 2001 From: Justwmz Date: Fri, 9 Feb 2024 16:39:42 -0500 Subject: [PATCH 1/4] Added possability to assign env var for VMSS --- plugins/inventory/azure_rm.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/azure_rm.py b/plugins/inventory/azure_rm.py index 8b8fc9dc7..a3c9e2ef9 100644 --- a/plugins/inventory/azure_rm.py +++ b/plugins/inventory/azure_rm.py @@ -288,8 +288,12 @@ def _get_hosts(self): for vm_rg in self.get_option('include_vm_resource_groups'): self._enqueue_vm_list(vm_rg) - for vmss_rg in self.get_option('include_vmss_resource_groups'): - self._enqueue_vmss_list(vmss_rg) + if os.environ.get('ANSIBLE_AZURE_VMSS_RESOURCE_GROUPS'): + for vm_rg in os.environ['ANSIBLE_AZURE_VMSS_RESOURCE_GROUPS'].split(","): + self._enqueue_vmss_list(vmss_rg) + else: + for vmss_rg in self.get_option('include_vmss_resource_groups'): + self._enqueue_vmss_list(vmss_rg) if self._batch_fetch: self._process_queue_batch() From 4bc40a91c621bca0cefcba00b904744aa97e8ab9 Mon Sep 17 00:00:00 2001 From: Justwmz Date: Fri, 9 Feb 2024 16:59:20 -0500 Subject: [PATCH 2/4] Fix typo --- plugins/inventory/azure_rm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inventory/azure_rm.py b/plugins/inventory/azure_rm.py index a3c9e2ef9..8fe78a64a 100644 --- a/plugins/inventory/azure_rm.py +++ b/plugins/inventory/azure_rm.py @@ -289,7 +289,7 @@ def _get_hosts(self): self._enqueue_vm_list(vm_rg) if os.environ.get('ANSIBLE_AZURE_VMSS_RESOURCE_GROUPS'): - for vm_rg in os.environ['ANSIBLE_AZURE_VMSS_RESOURCE_GROUPS'].split(","): + for vmss_rg in os.environ['ANSIBLE_AZURE_VMSS_RESOURCE_GROUPS'].split(","): self._enqueue_vmss_list(vmss_rg) else: for vmss_rg in self.get_option('include_vmss_resource_groups'): From 1d1e3a432447c47952ca450ec1e6ef70987edeb6 Mon Sep 17 00:00:00 2001 From: Justwmz Date: Fri, 9 Feb 2024 17:10:50 -0500 Subject: [PATCH 3/4] Fix inventory fail when trying to parse instances from the flexible scaleset. --- plugins/inventory/azure_rm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/inventory/azure_rm.py b/plugins/inventory/azure_rm.py index 8fe78a64a..4a377c6a9 100644 --- a/plugins/inventory/azure_rm.py +++ b/plugins/inventory/azure_rm.py @@ -407,6 +407,12 @@ def _on_vmss_page_response(self, response): # FUTURE: add direct VMSS filtering by tag here (performance optimization)? for vmss in response['value']: url = '{0}/virtualMachines'.format(vmss['id']) + + # Since Flexible instance is a standalone VM, we are replacing ss provider to the vm one in order to allow inventory get instance view. + if vmss['properties']['orchestrationMode'] == 'Flexible': + newProvider = 'Microsoft.Compute/virtualMachineScaleSets/{0}/virtualMachines'.format(vmss['name']) + url = url.replace(newProvider, "Microsoft.Compute/virtualMachines") + # VMSS instances look close enough to regular VMs that we can share the handler impl... self._enqueue_get(url=url, api_version=self._compute_api_version, handler=self._on_vm_page_response, handler_args=dict(vmss=vmss)) From 4a3623f92ca41e90eb179c29dc1b9db12c576e54 Mon Sep 17 00:00:00 2001 From: Justwmz Date: Fri, 23 Feb 2024 13:52:22 -0500 Subject: [PATCH 4/4] Filtering out flexible parent --- .vscode/settings.json | 5 +++++ plugins/inventory/azure_rm.py | 12 ++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..0b3dae468 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "dev" + ] +} \ No newline at end of file diff --git a/plugins/inventory/azure_rm.py b/plugins/inventory/azure_rm.py index 4a377c6a9..3d7c2e035 100644 --- a/plugins/inventory/azure_rm.py +++ b/plugins/inventory/azure_rm.py @@ -395,7 +395,6 @@ def _on_vm_page_response(self, response, vmss=None): if 'value' in response: for h in response['value']: - # FUTURE: add direct VM filtering by tag here (performance optimization)? self._hosts.append(AzureHost(h, self, vmss=vmss, legacy_name=self._legacy_hostnames)) def _on_vmss_page_response(self, response): @@ -408,13 +407,10 @@ def _on_vmss_page_response(self, response): for vmss in response['value']: url = '{0}/virtualMachines'.format(vmss['id']) - # Since Flexible instance is a standalone VM, we are replacing ss provider to the vm one in order to allow inventory get instance view. - if vmss['properties']['orchestrationMode'] == 'Flexible': - newProvider = 'Microsoft.Compute/virtualMachineScaleSets/{0}/virtualMachines'.format(vmss['name']) - url = url.replace(newProvider, "Microsoft.Compute/virtualMachines") - - # VMSS instances look close enough to regular VMs that we can share the handler impl... - self._enqueue_get(url=url, api_version=self._compute_api_version, handler=self._on_vm_page_response, handler_args=dict(vmss=vmss)) + # Since Flexible instance is a standalone VM we are processing them as regular VM. + if vmss['properties']['orchestrationMode'] != 'Flexible': + # VMSS instances look close enough to regular VMs that we can share the handler impl... + self._enqueue_get(url=url, api_version=self._compute_api_version, handler=self._on_vm_page_response, handler_args=dict(vmss=vmss)) # use the undocumented /batch endpoint to bulk-send up to 500 requests in a single round-trip #