mirror of
https://github.com/ansible/awx.git
synced 2026-03-13 15:09:32 -02:30
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.
This commit is contained in:
@@ -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']
|
||||
|
||||
Reference in New Issue
Block a user