From e3d39a2728936188491de88479f9665a98c60191 Mon Sep 17 00:00:00 2001 From: Gabe Muniz Date: Thu, 19 Jan 2023 12:40:14 -0500 Subject: [PATCH] push limit to inventory sources move limit field from InventorySourceSerializer to InventorySourceOptionsSerializer (#13464) InventorySourceOptionsSerializer is the parent for both InventorySourceSerializer and InventoryUpdateSerializer The limit option need to be exposed to both inventory_source and inventory_update Co-Authored-By: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> --- awx/api/serializers.py | 1 + awx/main/migrations/0175_constructed_inventory.py | 10 ++++++++++ awx/main/models/inventory.py | 7 ++++++- awx/main/tasks/jobs.py | 5 +++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index cafd51a835..f927347f63 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -2144,6 +2144,7 @@ class InventorySourceOptionsSerializer(BaseSerializer): 'custom_virtualenv', 'timeout', 'verbosity', + 'limit', ) read_only_fields = ('*', 'custom_virtualenv') diff --git a/awx/main/migrations/0175_constructed_inventory.py b/awx/main/migrations/0175_constructed_inventory.py index 1c43afc9f4..4e3309c5df 100644 --- a/awx/main/migrations/0175_constructed_inventory.py +++ b/awx/main/migrations/0175_constructed_inventory.py @@ -79,4 +79,14 @@ class Migration(migrations.Migration): max_length=32, ), ), + migrations.AddField( + model_name='inventorysource', + name='limit', + field=models.TextField(blank=True, default='', help_text='Enter host, group or pattern match'), + ), + migrations.AddField( + model_name='inventoryupdate', + name='limit', + field=models.TextField(blank=True, default='', help_text='Enter host, group or pattern match'), + ), ] diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 3f33420686..445f76a5cf 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -969,7 +969,7 @@ class InventorySourceOptions(BaseModel): host_filter = models.TextField( blank=True, default='', - help_text=_('Regex where only matching hosts will be imported.'), + help_text=_('This field is deprecated and will be removed in a future release. Regex where only matching hosts will be imported.'), ) overwrite = models.BooleanField( default=False, @@ -989,6 +989,11 @@ class InventorySourceOptions(BaseModel): blank=True, default=1, ) + limit = models.TextField( + blank=True, + default='', + help_text=_("Enter host, group or pattern match"), + ) @staticmethod def cloud_credential_validation(source, cred): diff --git a/awx/main/tasks/jobs.py b/awx/main/tasks/jobs.py index f11d676989..8a68a000d4 100644 --- a/awx/main/tasks/jobs.py +++ b/awx/main/tasks/jobs.py @@ -1542,6 +1542,11 @@ class RunInventoryUpdate(SourceControlMixin, BaseTask): args.append('-i') args.append(container_location) + # Added this in order to allow older versions of ansible-inventory https://github.com/ansible/ansible/pull/79596 + # limit should be usable in ansible-inventory 2.15+ + if inventory_update.limit: + args.append('--limit') + args.append(inventory_update.limit) args.append('--output') args.append(os.path.join(CONTAINER_ROOT, 'artifacts', str(inventory_update.id), 'output.json'))