From 1a4bb42ac5f519160d0bc24a9a48e27b72938518 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Mon, 6 Jul 2020 09:45:08 -0400 Subject: [PATCH] When using return_ids send back a list of strings instead of ints. When we used ints and passed this data into a nother call like: - name: Create a job template with a looked up credential from a folded lookup tower_job_template: name: "{{ job_template_name }}" credentials: >- {{ lookup( 'awx.awx.tower_api', 'credentials', query_params={ 'name' : credential_name }, return_ids=True, expect_one=True, wantlist=True ) }} project: "{{ project_name }}" inventory: Demo Inventory playbook: hello_world.yml job_type: run state: present register: create_jt Ansible would raise this warning: [WARNING]: The value 30 (type int) in a string field was converted to '30' (type string). If this does not look like what you expect, quote the entire value to ensure it does not change. Returning a list of strings prevents that. --- awx_collection/plugins/lookup/tower_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/awx_collection/plugins/lookup/tower_api.py b/awx_collection/plugins/lookup/tower_api.py index 2e30964a2d..58ef9c1490 100644 --- a/awx_collection/plugins/lookup/tower_api.py +++ b/awx_collection/plugins/lookup/tower_api.py @@ -52,6 +52,7 @@ options: description: - If response contains objects, promote the id key to the top-level entries in the list. - Allows looking up a related object and passing it as a parameter to another module. + - This will convert the return to a string or list of strings depending on the number of selected items. type: boolean aliases: [return_id] default: False @@ -160,9 +161,9 @@ class LookupModule(LookupBase): if self.get_option('return_ids'): if 'results' in return_data: - return_data['results'] = [item['id'] for item in return_data['results']] + return_data['results'] = [str(item['id']) for item in return_data['results']] elif 'id' in return_data: - return_data = return_data['id'] + return_data = str(return_data['id']) if self.get_option('return_objects') and 'results' in return_data: return return_data['results']