From bed3a9ee4134e51a50dde7f43c8fb3c6cdfeef00 Mon Sep 17 00:00:00 2001 From: sean-m-sullivan Date: Wed, 26 Aug 2020 08:11:51 -0500 Subject: [PATCH] added id lookup --- .../plugins/modules/tower_project_update.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/awx_collection/plugins/modules/tower_project_update.py b/awx_collection/plugins/modules/tower_project_update.py index e9f85321d5..4978052e5c 100644 --- a/awx_collection/plugins/modules/tower_project_update.py +++ b/awx_collection/plugins/modules/tower_project_update.py @@ -21,7 +21,7 @@ description: options: name: description: - - The name of the project to update. + - The name or id of the project to update. required: True type: str aliases: @@ -102,14 +102,19 @@ def main(): interval = module.params.get('interval') timeout = module.params.get('timeout') - # Attempt to look up project based on the provided name - lookup_data = {'name': name} - if organization: - lookup_data['organization'] = module.resolve_name_to_id('organizations', organization) - project = module.get_one('projects', data=lookup_data) - - if project is None: - module.fail_json(msg="Unable to find project") + # Attempt to look up project based on the provided name or id + if name.isnumeric(): + results = module.get_endpoint('projects', **{'data': {'id': name}}) + project = results['json']['results'][0] + if project is None: + module.fail_json(msg="Unable to find project") + else: + lookup_data = {'name': name} + if organization: + lookup_data['organization'] = module.resolve_name_to_id('organizations', organization) + project = module.get_one('projects', data=lookup_data) + if project is None: + module.fail_json(msg="Unable to find project") # Update the project result = module.post_endpoint(project['related']['update'])