mirror of
https://github.com/ansible/awx.git
synced 2026-05-11 19:37:38 -02:30
Make tower_api a generic GET'er
This commit is contained in:
@@ -23,7 +23,7 @@ options:
|
|||||||
description:
|
description:
|
||||||
- The query parameters to search for in the form of key/value pairs.
|
- The query parameters to search for in the form of key/value pairs.
|
||||||
type: dict
|
type: dict
|
||||||
required: True
|
required: False
|
||||||
get_all:
|
get_all:
|
||||||
description:
|
description:
|
||||||
- If the resulting query is paginated, return all pages.
|
- If the resulting query is paginated, return all pages.
|
||||||
@@ -36,6 +36,10 @@ notes:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
|
- name: Load the UI settings
|
||||||
|
debug:
|
||||||
|
msg: "{{ query('awx.awx.tower_api', 'settings/ui') }}"
|
||||||
|
|
||||||
- name: Lookup any users who are admins
|
- name: Lookup any users who are admins
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ query('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }) }}"
|
msg: "{{ query('awx.awx.tower_api', 'users', query_params={ 'is_superuser': true }) }}"
|
||||||
@@ -44,22 +48,9 @@ EXAMPLES = """
|
|||||||
RETURN = """
|
RETURN = """
|
||||||
_raw:
|
_raw:
|
||||||
description:
|
description:
|
||||||
- Response of objects from API
|
- Response from the API
|
||||||
type: dict
|
type: dict
|
||||||
contains:
|
returned: on successful request
|
||||||
count:
|
|
||||||
description: The number of objects your filter returned in total (not necessarally on this page)
|
|
||||||
type: str
|
|
||||||
next:
|
|
||||||
description: The URL path for the next page
|
|
||||||
type: str
|
|
||||||
previous:
|
|
||||||
description: The URL path for the previous page
|
|
||||||
type: str
|
|
||||||
results:
|
|
||||||
description: An array of results that were returned
|
|
||||||
type: list
|
|
||||||
returned: on successful create
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
@@ -98,12 +89,9 @@ class LookupModule(LookupBase):
|
|||||||
self.set_options(direct=kwargs)
|
self.set_options(direct=kwargs)
|
||||||
|
|
||||||
if self.get_option('get_all'):
|
if self.get_option('get_all'):
|
||||||
return_data = module.get_all_endpoint(terms[0], data=self.get_option('query_params'))
|
return_data = module.get_all_endpoint(terms[0], data=self.get_option('query_params', {} ), none_is_not_fatal=True)
|
||||||
else:
|
else:
|
||||||
return_data = module.get_endpoint(terms[0], data=self.get_option('query_params'))
|
return_data = module.get_endpoint(terms[0], data=self.get_option('query_params', {} ))
|
||||||
with open('/tmp/john', 'w') as f:
|
|
||||||
import json
|
|
||||||
f.write(json.dumps(return_data, indent=4))
|
|
||||||
|
|
||||||
if return_data['status_code'] != 200:
|
if return_data['status_code'] != 200:
|
||||||
error = return_data
|
error = return_data
|
||||||
|
|||||||
@@ -274,7 +274,10 @@ class TowerModule(AnsibleModule):
|
|||||||
def get_all_endpoint(self, endpoint, *args, **kwargs):
|
def get_all_endpoint(self, endpoint, *args, **kwargs):
|
||||||
response = self.get_endpoint(endpoint, *args, **kwargs)
|
response = self.get_endpoint(endpoint, *args, **kwargs)
|
||||||
if 'next' not in response['json']:
|
if 'next' not in response['json']:
|
||||||
raise RuntimeError('Expected list from API at {0}, got: {1}'.format(endpoint, response))
|
if not 'none_is_not_fatal' in kwargs or not kwargs['none_is_not_fatal']:
|
||||||
|
raise RuntimeError('Expected list from API at {0}, got: {1}'.format(endpoint, response))
|
||||||
|
else:
|
||||||
|
return response
|
||||||
next_page = response['json']['next']
|
next_page = response['json']['next']
|
||||||
|
|
||||||
if response['json']['count'] > 10000:
|
if response['json']['count'] > 10000:
|
||||||
|
|||||||
@@ -67,6 +67,26 @@
|
|||||||
that:
|
that:
|
||||||
- users['results'] | length() >= 3
|
- users['results'] | length() >= 3
|
||||||
|
|
||||||
|
- name: Get the settings page
|
||||||
|
set_fact:
|
||||||
|
settings: "{{ query('awx.awx.tower_api', 'settings/ui' ) }}"
|
||||||
|
register: results
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- results is succeeded
|
||||||
|
- "'CUSTOM_LOGO' in settings"
|
||||||
|
|
||||||
|
- name: Get the ping page
|
||||||
|
set_fact:
|
||||||
|
ping_data: "{{ query('awx.awx.tower_api', 'ping' ) }}"
|
||||||
|
register: results
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- results is succeeded
|
||||||
|
- "'active_node' in ping_data"
|
||||||
|
|
||||||
always:
|
always:
|
||||||
- name: Cleanup users
|
- name: Cleanup users
|
||||||
tower_user:
|
tower_user:
|
||||||
|
|||||||
Reference in New Issue
Block a user