mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-22 19:59:07 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -132,18 +132,18 @@ def main():
|
|||
module = AnsibleModule(
|
||||
supports_check_mode=True,
|
||||
argument_spec=dict(
|
||||
url=dict(type='str', required=True),
|
||||
api_key=dict(type='str', required=True, no_log=True),
|
||||
text=dict(type='str'),
|
||||
channel=dict(type='str'),
|
||||
username=dict(type='str', default='Ansible'),
|
||||
icon_url=dict(type='str', default='https://docs.ansible.com/favicon.ico'),
|
||||
priority=dict(type='str', choices=['important', 'urgent']),
|
||||
validate_certs=dict(default=True, type='bool'),
|
||||
attachments=dict(type='list', elements='dict'),
|
||||
url=dict(type="str", required=True),
|
||||
api_key=dict(type="str", required=True, no_log=True),
|
||||
text=dict(type="str"),
|
||||
channel=dict(type="str"),
|
||||
username=dict(type="str", default="Ansible"),
|
||||
icon_url=dict(type="str", default="https://docs.ansible.com/favicon.ico"),
|
||||
priority=dict(type="str", choices=["important", "urgent"]),
|
||||
validate_certs=dict(default=True, type="bool"),
|
||||
attachments=dict(type="list", elements="dict"),
|
||||
),
|
||||
required_one_of=[
|
||||
('text', 'attachments'),
|
||||
("text", "attachments"),
|
||||
],
|
||||
)
|
||||
# init return dict
|
||||
|
|
@ -151,23 +151,23 @@ def main():
|
|||
|
||||
# define webhook
|
||||
webhook_url = f"{module.params['url']}/hooks/{module.params['api_key']}"
|
||||
result['webhook_url'] = webhook_url
|
||||
result["webhook_url"] = webhook_url
|
||||
|
||||
# define payload
|
||||
payload = {}
|
||||
for param in ['text', 'channel', 'username', 'icon_url', 'attachments']:
|
||||
for param in ["text", "channel", "username", "icon_url", "attachments"]:
|
||||
if module.params[param] is not None:
|
||||
payload[param] = module.params[param]
|
||||
if module.params['priority'] is not None:
|
||||
payload['priority'] = {'priority': module.params['priority']}
|
||||
if module.params["priority"] is not None:
|
||||
payload["priority"] = {"priority": module.params["priority"]}
|
||||
|
||||
payload = module.jsonify(payload)
|
||||
result['payload'] = payload
|
||||
result["payload"] = payload
|
||||
|
||||
# http headers
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
}
|
||||
|
||||
# notes:
|
||||
|
|
@ -177,17 +177,17 @@ def main():
|
|||
|
||||
# send request if not in test mode
|
||||
if module.check_mode is False:
|
||||
response, info = fetch_url(module=module, url=webhook_url, headers=headers, method='POST', data=payload)
|
||||
response, info = fetch_url(module=module, url=webhook_url, headers=headers, method="POST", data=payload)
|
||||
|
||||
# something's wrong
|
||||
if info['status'] != 200:
|
||||
if info["status"] != 200:
|
||||
# some problem
|
||||
result['msg'] = f"Failed to send mattermost message, the error was: {info['msg']}"
|
||||
result["msg"] = f"Failed to send mattermost message, the error was: {info['msg']}"
|
||||
module.fail_json(**result)
|
||||
|
||||
# Looks good
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue