From 1ec1feb138d0a8099a9c0e6e5a8ba311222a648d Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 9 Dec 2022 09:16:41 -0500 Subject: [PATCH] Implement extra constructed inventory more generically --- awx/main/tasks/jobs.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/awx/main/tasks/jobs.py b/awx/main/tasks/jobs.py index 2f28ec74bed5..eaa23b5b279e 100644 --- a/awx/main/tasks/jobs.py +++ b/awx/main/tasks/jobs.py @@ -331,24 +331,23 @@ def build_inventory(self, instance, private_data_dir): script_params['slice_count'] = instance.job_slice_count self.runner_callback.host_map = {} + inv_paths = [] if instance.inventory.kind == 'multiple': - inv_paths = [] for source_inventory in instance.inventory.source_inventories.all(): inv_paths.append(self._write_inventory_file(source_inventory, private_data_dir, f'hosts_{source_inventory.id}', script_params)) + else: + inv_paths.append(self._write_inventory_file(instance.inventory, private_data_dir, 'hosts', script_params)) - # add any inventory sources from the inventory as just-in-time sources - for inv_source in instance.inventory.inventory_sources.filter(source='constructed'): - injector = InventorySource.injectors[inv_source.source]() - - content = injector.inventory_contents(inv_source, private_data_dir) - self.write_private_data_file(private_data_dir, injector.filename, content, sub_dir='inventory', file_permissions=0o700) - rel_path = os.path.join('inventory', injector.filename) - inv_paths.append(rel_path) + # add any inventory sources from the inventory as just-in-time sources + for inv_source in instance.inventory.inventory_sources.filter(source='constructed'): + injector = InventorySource.injectors[inv_source.source]() - self._write_inventory_file(instance.inventory, private_data_dir, 'hosts', script_params) + content = injector.inventory_contents(inv_source, private_data_dir) + self.write_private_data_file(private_data_dir, injector.filename, content, sub_dir='inventory', file_permissions=0o700) + rel_path = os.path.join('inventory', injector.filename) + inv_paths.append(rel_path) - else: - inv_paths = self._write_inventory_file(instance.inventory, private_data_dir, 'hosts', script_params) + self._write_inventory_file(instance.inventory, private_data_dir, 'hosts', script_params) return inv_paths