From 24bdbd8c58c7ae5bc56ed2558a6161399d8a08e2 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Wed, 16 Sep 2020 14:41:04 -0400 Subject: [PATCH 1/3] Fixing issue with lookup plugin not able to load host, user, etc --- awx_collection/plugins/lookup/tower_api.py | 4 ++-- .../targets/tower_lookup_api_plugin/tasks/main.yml | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/awx_collection/plugins/lookup/tower_api.py b/awx_collection/plugins/lookup/tower_api.py index 76b32be60a..8f0f3ab438 100644 --- a/awx_collection/plugins/lookup/tower_api.py +++ b/awx_collection/plugins/lookup/tower_api.py @@ -131,6 +131,8 @@ class LookupModule(LookupBase): if len(terms) != 1: raise AnsibleError('You must pass exactly one endpoint to query') + self.set_options(direct=kwargs) + # Defer processing of params to logic shared with the modules module_params = {} for plugin_param, module_param in TowerAPIModule.short_params.items(): @@ -144,8 +146,6 @@ class LookupModule(LookupBase): error_callback=self.handle_error, warn_callback=self.warn_callback ) - self.set_options(direct=kwargs) - response = module.get_endpoint(terms[0], data=self.get_option('query_params', {})) if 'status_code' not in response: diff --git a/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml b/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml index 9f29b0d9ab..cb8f628589 100644 --- a/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml @@ -32,6 +32,16 @@ register: user_creation_results - block: + - name: Specify the connection params + debug: + msg: "{{ query(plugin_name, 'ping', host='DNE://junk.com', username='john', password='not_legit', verify_ssl=True) }}" + register: results + ignore_errors: True + + - assert: + that: + - "'DNE' in results.msg" + - name: Create our hosts tower_host: name: "{{ item }}" From ee3a90d19331426133171f07ddc7dea9cdacacfe Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Wed, 16 Sep 2020 14:52:41 -0400 Subject: [PATCH 2/3] Adding example of specifying connection info --- awx_collection/plugins/lookup/tower_api.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/awx_collection/plugins/lookup/tower_api.py b/awx_collection/plugins/lookup/tower_api.py index 8f0f3ab438..a10d9c4c8e 100644 --- a/awx_collection/plugins/lookup/tower_api.py +++ b/awx_collection/plugins/lookup/tower_api.py @@ -72,6 +72,10 @@ EXAMPLES = """ set_fact: tower_settings: "{{ lookup('awx.awx.tower_api', 'settings/ui') }}" +- name: Load the UI settings specifying the connection info + set_fact: + tower_settings: "{{ lookup('awx.awx.tower_api', 'settings/ui' host='tower.example.com', username='admin', password=my_pass_var, verify_ssl=False) }}" + - name: Report the usernames of all users with admin privs debug: msg: "Admin users: {{ query('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }) | map(attribute='username') | join(', ') }}" From baa00bd58214ebe4bda337d7d401cc1946f62ce0 Mon Sep 17 00:00:00 2001 From: John Westcott IV Date: Thu, 17 Sep 2020 07:51:01 -0400 Subject: [PATCH 3/3] Truthy strikes again --- .../integration/targets/tower_lookup_api_plugin/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml b/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml index cb8f628589..9f5d42ac20 100644 --- a/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_lookup_api_plugin/tasks/main.yml @@ -36,7 +36,7 @@ debug: msg: "{{ query(plugin_name, 'ping', host='DNE://junk.com', username='john', password='not_legit', verify_ssl=True) }}" register: results - ignore_errors: True + ignore_errors: true - assert: that: