mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 21:33:12 +00:00
Reformat everything.
This commit is contained in:
@@ -141,67 +141,66 @@ from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
component=dict(required=True, aliases=['name']),
|
||||
component=dict(required=True, aliases=["name"]),
|
||||
version=dict(required=True),
|
||||
token=dict(required=True, no_log=True),
|
||||
state=dict(required=True, choices=['started', 'finished', 'failed']),
|
||||
hosts=dict(aliases=['host']),
|
||||
state=dict(required=True, choices=["started", "finished", "failed"]),
|
||||
hosts=dict(aliases=["host"]),
|
||||
env=dict(),
|
||||
owner=dict(),
|
||||
description=dict(),
|
||||
deployment_message=dict(),
|
||||
source_system=dict(default='ansible'),
|
||||
validate_certs=dict(default=True, type='bool'),
|
||||
url=dict(default='https://api.bigpanda.io'),
|
||||
source_system=dict(default="ansible"),
|
||||
validate_certs=dict(default=True, type="bool"),
|
||||
url=dict(default="https://api.bigpanda.io"),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
token = module.params['token']
|
||||
state = module.params['state']
|
||||
url = module.params['url']
|
||||
token = module.params["token"]
|
||||
state = module.params["state"]
|
||||
url = module.params["url"]
|
||||
|
||||
# Build the common request body
|
||||
body = dict()
|
||||
for k in ('component', 'version', 'hosts'):
|
||||
for k in ("component", "version", "hosts"):
|
||||
v = module.params[k]
|
||||
if v is not None:
|
||||
body[k] = v
|
||||
if body.get('hosts') is None:
|
||||
body['hosts'] = [socket.gethostname()]
|
||||
if body.get("hosts") is None:
|
||||
body["hosts"] = [socket.gethostname()]
|
||||
|
||||
if not isinstance(body['hosts'], list):
|
||||
body['hosts'] = [body['hosts']]
|
||||
if not isinstance(body["hosts"], list):
|
||||
body["hosts"] = [body["hosts"]]
|
||||
|
||||
# Insert state-specific attributes to body
|
||||
if state == 'started':
|
||||
for k in ('source_system', 'env', 'owner', 'description'):
|
||||
if state == "started":
|
||||
for k in ("source_system", "env", "owner", "description"):
|
||||
v = module.params[k]
|
||||
if v is not None:
|
||||
body[k] = v
|
||||
|
||||
request_url = f"{url}/data/events/deployments/start"
|
||||
else:
|
||||
message = module.params['deployment_message']
|
||||
message = module.params["deployment_message"]
|
||||
if message is not None:
|
||||
body['errorMessage'] = message
|
||||
body["errorMessage"] = message
|
||||
|
||||
if state == 'finished':
|
||||
body['status'] = 'success'
|
||||
if state == "finished":
|
||||
body["status"] = "success"
|
||||
else:
|
||||
body['status'] = 'failure'
|
||||
body["status"] = "failure"
|
||||
|
||||
request_url = f"{url}/data/events/deployments/end"
|
||||
|
||||
# Build the deployment object we return
|
||||
deployment = dict(token=token, url=url)
|
||||
deployment.update(body)
|
||||
if 'errorMessage' in deployment:
|
||||
message = deployment.pop('errorMessage')
|
||||
deployment['message'] = message
|
||||
if "errorMessage" in deployment:
|
||||
message = deployment.pop("errorMessage")
|
||||
deployment["message"] = message
|
||||
|
||||
# If we're in check mode, just exit pretending like we succeeded
|
||||
if module.check_mode:
|
||||
@@ -209,10 +208,10 @@ def main():
|
||||
|
||||
# Send the data to bigpanda
|
||||
data = json.dumps(body)
|
||||
headers = {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'}
|
||||
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
|
||||
try:
|
||||
response, info = fetch_url(module, request_url, data=data, headers=headers)
|
||||
if info['status'] == 200:
|
||||
if info["status"] == 200:
|
||||
module.exit_json(changed=True, **deployment)
|
||||
else:
|
||||
module.fail_json(msg=json.dumps(info))
|
||||
@@ -220,5 +219,5 @@ def main():
|
||||
module.fail_json(msg=to_native(e), exception=traceback.format_exc())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user