mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 02:17:37 -02:30
Merge pull request #583 from ansible/nicer_error_tower_inventory
Present the tower inventory sync failure in a better way
This commit is contained in:
@@ -68,8 +68,7 @@ def parse_configuration():
|
|||||||
if not inventory:
|
if not inventory:
|
||||||
errors.append("Missing TOWER_INVENTORY in environment")
|
errors.append("Missing TOWER_INVENTORY in environment")
|
||||||
if errors:
|
if errors:
|
||||||
print("\n".join(errors))
|
raise RuntimeError("\n".join(errors))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return dict(tower_host=host_name,
|
return dict(tower_host=host_name,
|
||||||
tower_user=username,
|
tower_user=username,
|
||||||
@@ -92,12 +91,10 @@ def read_tower_inventory(tower_host, tower_user, tower_pass, inventory, license_
|
|||||||
if config_response.ok:
|
if config_response.ok:
|
||||||
source_type = config_response.json()['license_info']['license_type']
|
source_type = config_response.json()['license_info']['license_type']
|
||||||
if not source_type == license_type:
|
if not source_type == license_type:
|
||||||
print("Tower server licenses must match: source: {} local: {}".format(source_type,
|
raise RuntimeError("Tower server licenses must match: source: {} local: {}".format(source_type,
|
||||||
license_type))
|
license_type))
|
||||||
sys.exit(1)
|
|
||||||
else:
|
else:
|
||||||
print("Failed to validate the license of the remote Tower: {}".format(config_response.data))
|
raise RuntimeError("Failed to validate the license of the remote Tower: {}".format(config_response.data))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
response = requests.get(inventory_url,
|
response = requests.get(inventory_url,
|
||||||
auth=HTTPBasicAuth(tower_user, tower_pass),
|
auth=HTTPBasicAuth(tower_user, tower_pass),
|
||||||
@@ -110,8 +107,7 @@ def read_tower_inventory(tower_host, tower_user, tower_pass, inventory, license_
|
|||||||
reason = "Connection to remote host failed: {}".format(e)
|
reason = "Connection to remote host failed: {}".format(e)
|
||||||
except json.JSONDecodeError, e:
|
except json.JSONDecodeError, e:
|
||||||
reason = "Failed to parse json from host: {}".format(e)
|
reason = "Failed to parse json from host: {}".format(e)
|
||||||
print(reason)
|
raise RuntimeError(reason)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -128,5 +124,6 @@ def main():
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user