mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 03:17:39 -02:30
Raise AnsibleParserError via a custom exception
This commit is contained in:
@@ -103,11 +103,11 @@ import re
|
|||||||
|
|
||||||
from ansible.module_utils import six
|
from ansible.module_utils import six
|
||||||
from ansible.module_utils._text import to_text, to_native
|
from ansible.module_utils._text import to_text, to_native
|
||||||
from ansible.errors import AnsibleOptionsError
|
from ansible.errors import AnsibleParserError, AnsibleOptionsError
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin
|
from ansible.plugins.inventory import BaseInventoryPlugin
|
||||||
from ansible.config.manager import ensure_type
|
from ansible.config.manager import ensure_type
|
||||||
|
|
||||||
from ..module_utils.ansible_tower import make_request, Request
|
from ..module_utils.ansible_tower import make_request, CollectionsParserError, Request
|
||||||
|
|
||||||
# Python 2/3 Compatibility
|
# Python 2/3 Compatibility
|
||||||
try:
|
try:
|
||||||
@@ -162,7 +162,11 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
inventory_url = '/api/v2/inventories/{inv_id}/script/?hostvars=1&towervars=1&all=1'.format(inv_id=inventory_id)
|
inventory_url = '/api/v2/inventories/{inv_id}/script/?hostvars=1&towervars=1&all=1'.format(inv_id=inventory_id)
|
||||||
inventory_url = urljoin(tower_host, inventory_url)
|
inventory_url = urljoin(tower_host, inventory_url)
|
||||||
|
|
||||||
inventory = make_request(request_handler, inventory_url)
|
try:
|
||||||
|
inventory = make_request(request_handler, inventory_url)
|
||||||
|
except CollectionsParserError as e:
|
||||||
|
raise AnsibleParserError(to_native(e))
|
||||||
|
|
||||||
# To start with, create all the groups.
|
# To start with, create all the groups.
|
||||||
for group_name in inventory:
|
for group_name in inventory:
|
||||||
if group_name != '_meta':
|
if group_name != '_meta':
|
||||||
@@ -192,7 +196,12 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
# Fetch extra variables if told to do so
|
# Fetch extra variables if told to do so
|
||||||
if self.get_option('include_metadata'):
|
if self.get_option('include_metadata'):
|
||||||
config_url = urljoin(tower_host, '/api/v2/config/')
|
config_url = urljoin(tower_host, '/api/v2/config/')
|
||||||
config_data = make_request(request_handler, config_url)
|
|
||||||
|
try:
|
||||||
|
config_data = make_request(request_handler, config_url)
|
||||||
|
except CollectionsParserError as e:
|
||||||
|
raise AnsibleParserError(to_native(e))
|
||||||
|
|
||||||
server_data = {}
|
server_data = {}
|
||||||
server_data['license_type'] = config_data.get('license_info', {}).get('license_type', 'unknown')
|
server_data['license_type'] = config_data.get('license_info', {}).get('license_type', 'unknown')
|
||||||
for key in ('version', 'ansible_version'):
|
for key in ('version', 'ansible_version'):
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ except ImportError:
|
|||||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionsParserError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def make_request(request_handler, tower_url):
|
def make_request(request_handler, tower_url):
|
||||||
'''
|
'''
|
||||||
Makes the request to given URL, handles errors, returns JSON
|
Makes the request to given URL, handles errors, returns JSON
|
||||||
@@ -141,7 +145,3 @@ class TowerModule(AnsibleModule):
|
|||||||
if not HAS_TOWER_CLI:
|
if not HAS_TOWER_CLI:
|
||||||
self.fail_json(msg=missing_required_lib('ansible-tower-cli'),
|
self.fail_json(msg=missing_required_lib('ansible-tower-cli'),
|
||||||
exception=TOWER_CLI_IMP_ERR)
|
exception=TOWER_CLI_IMP_ERR)
|
||||||
|
|
||||||
|
|
||||||
class CollectionsParserError(Exception):
|
|
||||||
pass
|
|
||||||
|
|||||||
Reference in New Issue
Block a user