Skip to content

Commit

Permalink
Implement extra constructed inventory more generically
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Dec 9, 2022
1 parent 77f71ca commit 1ec1feb
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions awx/main/tasks/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1ec1feb

Please sign in to comment.