From 325e566a3d2e851d01c8e7f9fb9d3389ab419e4a Mon Sep 17 00:00:00 2001 From: Gabe Muniz Date: Thu, 19 Jan 2023 12:40:14 -0500 Subject: [PATCH 1/2] pushing limit to inventory sources --- awx/main/migrations/0175_constructed_inventory.py | 10 ++++++++++ awx/main/models/inventory.py | 7 ++++++- awx/main/tasks/jobs.py | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) 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 d6ff1be5a2..a592757295 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -925,7 +925,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, @@ -945,6 +945,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 9619cee0f1..c2e432f5d4 100644 --- a/awx/main/tasks/jobs.py +++ b/awx/main/tasks/jobs.py @@ -1539,6 +1539,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')) From 6351e8bbc9a7a3ca483f8736359b17d84d6f3f0a Mon Sep 17 00:00:00 2001 From: Gabe Muniz Date: Thu, 19 Jan 2023 13:01:45 -0500 Subject: [PATCH 2/2] added new migration for deprecation of host_filter --- .../migrations/0175_constructed_inventory.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/awx/main/migrations/0175_constructed_inventory.py b/awx/main/migrations/0175_constructed_inventory.py index 4e3309c5df..37085186d4 100644 --- a/awx/main/migrations/0175_constructed_inventory.py +++ b/awx/main/migrations/0175_constructed_inventory.py @@ -89,4 +89,22 @@ class Migration(migrations.Migration): name='limit', field=models.TextField(blank=True, default='', help_text='Enter host, group or pattern match'), ), + migrations.AlterField( + model_name='inventorysource', + name='host_filter', + field=models.TextField( + blank=True, + default='', + help_text='This field is deprecated and will be removed in a future release. Regex where only matching hosts will be imported.', + ), + ), + migrations.AlterField( + model_name='inventoryupdate', + name='host_filter', + field=models.TextField( + blank=True, + default='', + help_text='This field is deprecated and will be removed in a future release. Regex where only matching hosts will be imported.', + ), + ), ]