From 0424370d49b6e238e6ef52db5e2b1766e31967e3 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Mon, 6 Jul 2020 09:48:28 -0400 Subject: [PATCH] Revamp of the examples --- awx_collection/plugins/lookup/tower_api.py | 39 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/awx_collection/plugins/lookup/tower_api.py b/awx_collection/plugins/lookup/tower_api.py index 58ef9c1490..067604fe79 100644 --- a/awx_collection/plugins/lookup/tower_api.py +++ b/awx_collection/plugins/lookup/tower_api.py @@ -70,12 +70,43 @@ notes: EXAMPLES = """ - name: Load the UI settings - debug: - msg: "{{ query('awx.awx.tower_api', 'settings/ui') }}" + set_fact: + tower_settings: "{{ lookup('awx.awx.tower_api', 'settings/ui') }}" - name: Lookup any users who are admins - debug: - msg: "{{ query('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }) }}" + set_fact: + admin_user_list_view: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }, return_objects=False) }}" + +- name: Lookup any users who are admins and get their objects directly + set_fact: + admin_user_object: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true } ) }}" + +- name: Lookup the admin user and fail if there are more than one, and make sure its a list (without this, the response would be an object) + set_fact: + actual_admin_user: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'username': 'admin' }, expect_one=True, wantlist=True) }}" + +- name: Get just the user ID of the admin user + set_fact: + admin_user_id: "{{ lookup('awx.awx.tower_api', 'users', query_params={ 'username': 'admin' }, return_ids=True, expect_one=True) }}" + +- 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 """ RETURN = """