mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Bulk autopep8 (modules)
As agreed in 2017-12-07 Core meeting bulk fix pep8 issues Generated using: autopep8 1.3.3 (pycodestyle: 2.3.1) autopep8 -r --max-line-length 160 --in-place --ignore E305,E402,E722,E741 lib/ansible/modules Manually fix issues that autopep8 has introduced
This commit is contained in:
committed by
John R Barker
parent
d13d7e9404
commit
c57a7f05e1
@@ -122,21 +122,21 @@ def main():
|
||||
|
||||
target_url = '%s/room/%s/speak.xml' % (URI, room)
|
||||
headers = {'Content-Type': 'application/xml',
|
||||
'User-agent': AGENT}
|
||||
'User-agent': AGENT}
|
||||
|
||||
# Send some audible notification if requested
|
||||
if notify:
|
||||
response, info = fetch_url(module, target_url, data=NSTR % cgi.escape(notify), headers=headers)
|
||||
if info['status'] not in [200, 201]:
|
||||
module.fail_json(msg="unable to send msg: '%s', campfire api"
|
||||
" returned error code: '%s'" %
|
||||
" returned error code: '%s'" %
|
||||
(notify, info['status']))
|
||||
|
||||
# Send the message
|
||||
response, info = fetch_url(module, target_url, data=MSTR %cgi.escape(msg), headers=headers)
|
||||
response, info = fetch_url(module, target_url, data=MSTR % cgi.escape(msg), headers=headers)
|
||||
if info['status'] not in [200, 201]:
|
||||
module.fail_json(msg="unable to send msg: '%s', campfire api"
|
||||
" returned error code: '%s'" %
|
||||
" returned error code: '%s'" %
|
||||
(msg, info['status']))
|
||||
|
||||
module.exit_json(changed=True, room=room, msg=msg, notify=notify)
|
||||
|
||||
@@ -115,7 +115,7 @@ def main():
|
||||
argument_spec=dict(
|
||||
token=dict(required=True, no_log=True),
|
||||
msg=dict(required=True),
|
||||
type=dict(required=True, choices=["inbox","chat"]),
|
||||
type=dict(required=True, choices=["inbox", "chat"]),
|
||||
external_user_name=dict(required=False),
|
||||
from_address=dict(required=False),
|
||||
source=dict(required=False),
|
||||
@@ -125,7 +125,7 @@ def main():
|
||||
project=dict(required=False),
|
||||
tags=dict(required=False),
|
||||
link=dict(required=False),
|
||||
validate_certs = dict(default='yes', type='bool'),
|
||||
validate_certs=dict(default='yes', type='bool'),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
@@ -152,7 +152,7 @@ def main():
|
||||
module.fail_json(msg="external_user_name is required for the 'chat' type")
|
||||
|
||||
# required params for the 'inbox' type
|
||||
for item in [ 'from_address', 'source', 'subject' ]:
|
||||
for item in ['from_address', 'source', 'subject']:
|
||||
if module.params[item]:
|
||||
if type == 'chat':
|
||||
module.fail_json(msg="%s is not valid for the 'chat' type" % item)
|
||||
@@ -166,7 +166,7 @@ def main():
|
||||
params['tags'] = module.params["tags"]
|
||||
|
||||
# optional params for the 'inbox' type
|
||||
for item in [ 'from_name', 'reply_to', 'project', 'link' ]:
|
||||
for item in ['from_name', 'reply_to', 'project', 'link']:
|
||||
if module.params[item]:
|
||||
if type == 'chat':
|
||||
module.fail_json(msg="%s is not valid for the 'chat' type" % item)
|
||||
|
||||
@@ -71,6 +71,7 @@ BASE_URL = 'https://grove.io/api/notice/%s/'
|
||||
# ==============================================================
|
||||
# do_notify_grove
|
||||
|
||||
|
||||
def do_notify_grove(module, channel_token, service, message, url=None, icon_url=None):
|
||||
my_url = BASE_URL % (channel_token,)
|
||||
|
||||
@@ -88,15 +89,16 @@ def do_notify_grove(module, channel_token, service, message, url=None, icon_url=
|
||||
# ==============================================================
|
||||
# main
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
channel_token = dict(type='str', required=True, no_log=True),
|
||||
message = dict(type='str', required=True),
|
||||
service = dict(type='str', default='ansible'),
|
||||
url = dict(type='str', default=None),
|
||||
icon_url = dict(type='str', default=None),
|
||||
validate_certs = dict(default='yes', type='bool'),
|
||||
argument_spec=dict(
|
||||
channel_token=dict(type='str', required=True, no_log=True),
|
||||
message=dict(type='str', required=True),
|
||||
service=dict(type='str', default='ansible'),
|
||||
url=dict(type='str', default=None),
|
||||
icon_url=dict(type='str', default=None),
|
||||
validate_certs=dict(default='yes', type='bool'),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -62,12 +62,12 @@ from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
HALL_API_ENDPOINT = 'https://hall.com/api/1/services/generic/%s'
|
||||
HALL_API_ENDPOINT = 'https://hall.com/api/1/services/generic/%s'
|
||||
|
||||
|
||||
def send_request_to_hall(module, room_token, payload):
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
payload=module.jsonify(payload)
|
||||
payload = module.jsonify(payload)
|
||||
api_endpoint = HALL_API_ENDPOINT % (room_token)
|
||||
response, info = fetch_url(module, api_endpoint, data=payload, headers=headers)
|
||||
if info['status'] != 200:
|
||||
|
||||
@@ -259,11 +259,11 @@ def main():
|
||||
nick_to=dict(required=False, type='list'),
|
||||
msg=dict(required=True),
|
||||
color=dict(default="none", aliases=['colour'], choices=["white", "black", "blue",
|
||||
"green", "red", "brown",
|
||||
"purple", "orange", "yellow",
|
||||
"light_green", "teal", "light_cyan",
|
||||
"light_blue", "pink", "gray",
|
||||
"light_gray", "none"]),
|
||||
"green", "red", "brown",
|
||||
"purple", "orange", "yellow",
|
||||
"light_green", "teal", "light_cyan",
|
||||
"light_blue", "pink", "gray",
|
||||
"light_gray", "none"]),
|
||||
style=dict(default="none", choices=["underline", "reverse", "bold", "italic", "none"]),
|
||||
channel=dict(required=False),
|
||||
key=dict(no_log=True),
|
||||
|
||||
@@ -105,7 +105,7 @@ def main():
|
||||
to=dict(required=True),
|
||||
msg=dict(required=True),
|
||||
host=dict(required=False),
|
||||
port=dict(required=False,default=5222),
|
||||
port=dict(required=False, default=5222),
|
||||
encoding=dict(required=False),
|
||||
),
|
||||
supports_check_mode=True
|
||||
@@ -134,15 +134,15 @@ def main():
|
||||
msg = xmpp.protocol.Message(body=module.params['msg'])
|
||||
|
||||
try:
|
||||
conn=xmpp.Client(server, debug=[])
|
||||
if not conn.connect(server=(host,port)):
|
||||
conn = xmpp.Client(server, debug=[])
|
||||
if not conn.connect(server=(host, port)):
|
||||
module.fail_json(rc=1, msg='Failed to connect to server: %s' % (server))
|
||||
if not conn.auth(user,password,'Ansible'):
|
||||
module.fail_json(rc=1, msg='Failed to authorize %s on: %s' % (user,server))
|
||||
if not conn.auth(user, password, 'Ansible'):
|
||||
module.fail_json(rc=1, msg='Failed to authorize %s on: %s' % (user, server))
|
||||
# some old servers require this, also the sleep following send
|
||||
conn.sendInitPresence(requestRoster=0)
|
||||
|
||||
if nick: # sending to room instead of user, need to join
|
||||
if nick: # sending to room instead of user, need to join
|
||||
msg.setType('groupchat')
|
||||
msg.setTag('x', namespace='http://jabber.org/protocol/muc#user')
|
||||
conn.send(xmpp.Presence(to=module.params['to']))
|
||||
|
||||
@@ -98,54 +98,54 @@ from ansible.module_utils.urls import fetch_url
|
||||
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', required=True),
|
||||
channel = dict(type='str', default=None),
|
||||
username = dict(type='str', default='Ansible'),
|
||||
icon_url = dict(type='str', default='https://www.ansible.com/favicon.ico'),
|
||||
validate_certs = dict(default='yes', type='bool'),
|
||||
argument_spec=dict(
|
||||
url=dict(type='str', required=True),
|
||||
api_key=dict(type='str', required=True, no_log=True),
|
||||
text=dict(type='str', required=True),
|
||||
channel=dict(type='str', default=None),
|
||||
username=dict(type='str', default='Ansible'),
|
||||
icon_url=dict(type='str', default='https://www.ansible.com/favicon.ico'),
|
||||
validate_certs=dict(default='yes', type='bool'),
|
||||
)
|
||||
)
|
||||
#init return dict
|
||||
# init return dict
|
||||
result = dict(changed=False, msg="OK")
|
||||
|
||||
#define webhook
|
||||
webhook_url = "{0}/hooks/{1}".format(module.params['url'],module.params['api_key'])
|
||||
# define webhook
|
||||
webhook_url = "{0}/hooks/{1}".format(module.params['url'], module.params['api_key'])
|
||||
result['webhook_url'] = webhook_url
|
||||
|
||||
#define payload
|
||||
payload = { }
|
||||
# define payload
|
||||
payload = {}
|
||||
for param in ['text', 'channel', 'username', 'icon_url']:
|
||||
if module.params[param] is not None:
|
||||
payload[param] = module.params[param]
|
||||
|
||||
payload=module.jsonify(payload)
|
||||
payload = module.jsonify(payload)
|
||||
result['payload'] = payload
|
||||
|
||||
#http headers
|
||||
# http headers
|
||||
headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
|
||||
#notes:
|
||||
#Nothing is done in check mode
|
||||
#it'll pass even if your server is down or/and if your token is invalid.
|
||||
#If someone find good way to check...
|
||||
# notes:
|
||||
# Nothing is done in check mode
|
||||
# it'll pass even if your server is down or/and if your token is invalid.
|
||||
# If someone find good way to check...
|
||||
|
||||
#send request if not in test mode
|
||||
# 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)
|
||||
|
||||
#something's wrong
|
||||
# something's wrong
|
||||
if info['status'] != 200:
|
||||
#some problem
|
||||
# some problem
|
||||
result['msg'] = "Failed to send mattermost message, the error was: {0}".format(info['msg'])
|
||||
module.fail_json(**result)
|
||||
|
||||
#Looks good
|
||||
# Looks good
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
||||
@@ -144,18 +144,18 @@ def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
server = dict(default = 'localhost'),
|
||||
port = dict(default = 1883, type='int'),
|
||||
topic = dict(required = True),
|
||||
payload = dict(required = True),
|
||||
client_id = dict(default = None),
|
||||
qos = dict(default="0", choices=["0", "1", "2"]),
|
||||
retain = dict(default=False, type='bool'),
|
||||
username = dict(default = None),
|
||||
password = dict(default = None, no_log=True),
|
||||
ca_certs = dict(default = None, type='path'),
|
||||
certfile = dict(default = None, type='path'),
|
||||
keyfile = dict(default = None, type='path'),
|
||||
server=dict(default='localhost'),
|
||||
port=dict(default=1883, type='int'),
|
||||
topic=dict(required=True),
|
||||
payload=dict(required=True),
|
||||
client_id=dict(default=None),
|
||||
qos=dict(default="0", choices=["0", "1", "2"]),
|
||||
retain=dict(default=False, type='bool'),
|
||||
username=dict(default=None),
|
||||
password=dict(default=None, no_log=True),
|
||||
ca_certs=dict(default=None, type='path'),
|
||||
certfile=dict(default=None, type='path'),
|
||||
keyfile=dict(default=None, type='path'),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
@@ -163,18 +163,18 @@ def main():
|
||||
if not HAS_PAHOMQTT:
|
||||
module.fail_json(msg="Paho MQTT is not installed")
|
||||
|
||||
server = module.params.get("server", 'localhost')
|
||||
port = module.params.get("port", 1883)
|
||||
topic = module.params.get("topic")
|
||||
payload = module.params.get("payload")
|
||||
client_id = module.params.get("client_id", '')
|
||||
qos = int(module.params.get("qos", 0))
|
||||
retain = module.params.get("retain")
|
||||
username = module.params.get("username", None)
|
||||
password = module.params.get("password", None)
|
||||
ca_certs = module.params.get("ca_certs", None)
|
||||
certfile = module.params.get("certfile", None)
|
||||
keyfile = module.params.get("keyfile", None)
|
||||
server = module.params.get("server", 'localhost')
|
||||
port = module.params.get("port", 1883)
|
||||
topic = module.params.get("topic")
|
||||
payload = module.params.get("payload")
|
||||
client_id = module.params.get("client_id", '')
|
||||
qos = int(module.params.get("qos", 0))
|
||||
retain = module.params.get("retain")
|
||||
username = module.params.get("username", None)
|
||||
password = module.params.get("password", None)
|
||||
ca_certs = module.params.get("ca_certs", None)
|
||||
certfile = module.params.get("certfile", None)
|
||||
keyfile = module.params.get("keyfile", None)
|
||||
|
||||
if client_id is None:
|
||||
client_id = "%s_%s" % (socket.getfqdn(), os.getpid())
|
||||
@@ -182,11 +182,11 @@ def main():
|
||||
if payload and payload == 'None':
|
||||
payload = None
|
||||
|
||||
auth=None
|
||||
auth = None
|
||||
if username is not None:
|
||||
auth = { 'username' : username, 'password' : password }
|
||||
auth = {'username': username, 'password': password}
|
||||
|
||||
tls=None
|
||||
tls = None
|
||||
if ca_certs is not None:
|
||||
tls = {'ca_certs': ca_certs, 'certfile': certfile,
|
||||
'keyfile': keyfile}
|
||||
|
||||
@@ -48,7 +48,7 @@ import os
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
DEFAULT_VOICE='Alex'
|
||||
DEFAULT_VOICE = 'Alex'
|
||||
|
||||
|
||||
def say(module, msg, voice):
|
||||
@@ -68,7 +68,7 @@ def main():
|
||||
if not os.path.exists("/usr/bin/say"):
|
||||
module.fail_json(msg="/usr/bin/say is not installed")
|
||||
|
||||
msg = module.params['msg']
|
||||
msg = module.params['msg']
|
||||
voice = module.params['voice']
|
||||
|
||||
say(module, msg, voice)
|
||||
|
||||
@@ -107,28 +107,28 @@ from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
api_key = dict(type='str', required=True, no_log=True),
|
||||
channel = dict(type='str', default=None),
|
||||
device = dict(type='str', default=None),
|
||||
push_type = dict(type='str', default="note", choices=['note', 'link']),
|
||||
title = dict(type='str', required=True),
|
||||
body = dict(type='str', default=None),
|
||||
url = dict(type='str', default=None),
|
||||
argument_spec=dict(
|
||||
api_key=dict(type='str', required=True, no_log=True),
|
||||
channel=dict(type='str', default=None),
|
||||
device=dict(type='str', default=None),
|
||||
push_type=dict(type='str', default="note", choices=['note', 'link']),
|
||||
title=dict(type='str', required=True),
|
||||
body=dict(type='str', default=None),
|
||||
url=dict(type='str', default=None),
|
||||
),
|
||||
mutually_exclusive = (
|
||||
mutually_exclusive=(
|
||||
['channel', 'device'],
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
api_key = module.params['api_key']
|
||||
channel = module.params['channel']
|
||||
device = module.params['device']
|
||||
push_type = module.params['push_type']
|
||||
title = module.params['title']
|
||||
body = module.params['body']
|
||||
url = module.params['url']
|
||||
api_key = module.params['api_key']
|
||||
channel = module.params['channel']
|
||||
device = module.params['device']
|
||||
push_type = module.params['push_type']
|
||||
title = module.params['title']
|
||||
body = module.params['body']
|
||||
url = module.params['url']
|
||||
|
||||
if not pushbullet_found:
|
||||
module.fail_json(msg="Python 'pushbullet.py' module is required. Install via: $ pip install pushbullet.py")
|
||||
|
||||
@@ -73,12 +73,12 @@ class Pushover(object):
|
||||
|
||||
# parse config
|
||||
options = dict(user=self.user,
|
||||
token=self.token,
|
||||
priority=priority,
|
||||
message=msg)
|
||||
token=self.token,
|
||||
priority=priority,
|
||||
message=msg)
|
||||
data = urlencode(options)
|
||||
|
||||
headers = { "Content-type": "application/x-www-form-urlencoded"}
|
||||
headers = {"Content-type": "application/x-www-form-urlencoded"}
|
||||
r, info = fetch_url(self.module, url, method='POST', data=data, headers=headers)
|
||||
if info['status'] != 200:
|
||||
raise Exception(info)
|
||||
@@ -93,7 +93,7 @@ def main():
|
||||
msg=dict(required=True),
|
||||
app_token=dict(required=True, no_log=True),
|
||||
user_key=dict(required=True, no_log=True),
|
||||
pri=dict(required=False, default='0', choices=['-2','-1','0','1','2']),
|
||||
pri=dict(required=False, default='0', choices=['-2', '-1', '0', '1', '2']),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -196,9 +196,10 @@ def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon
|
||||
attachment['fallback'] = attachment['text']
|
||||
payload['attachments'].append(attachment)
|
||||
|
||||
payload="payload=" + module.jsonify(payload)
|
||||
payload = "payload=" + module.jsonify(payload)
|
||||
return payload
|
||||
|
||||
|
||||
def do_notify_rocketchat(module, domain, token, protocol, payload):
|
||||
|
||||
if token.count('/') < 1:
|
||||
@@ -210,21 +211,22 @@ def do_notify_rocketchat(module, domain, token, protocol, payload):
|
||||
if info['status'] != 200:
|
||||
module.fail_json(msg="failed to send message, return status=%s" % str(info['status']))
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
domain = dict(type='str', required=True, default=None),
|
||||
token = dict(type='str', required=True, no_log=True),
|
||||
protocol = dict(type='str', default='https', choices=['http', 'https']),
|
||||
msg = dict(type='str', required=False, default=None),
|
||||
channel = dict(type='str', default=None),
|
||||
username = dict(type='str', default='Ansible'),
|
||||
icon_url = dict(type='str', default='https://www.ansible.com/favicon.ico'),
|
||||
icon_emoji = dict(type='str', default=None),
|
||||
link_names = dict(type='int', default=1, choices=[0,1]),
|
||||
validate_certs = dict(default='yes', type='bool'),
|
||||
color = dict(type='str', default='normal', choices=['normal', 'good', 'warning', 'danger']),
|
||||
attachments = dict(type='list', required=False, default=None)
|
||||
argument_spec=dict(
|
||||
domain=dict(type='str', required=True, default=None),
|
||||
token=dict(type='str', required=True, no_log=True),
|
||||
protocol=dict(type='str', default='https', choices=['http', 'https']),
|
||||
msg=dict(type='str', required=False, default=None),
|
||||
channel=dict(type='str', default=None),
|
||||
username=dict(type='str', default='Ansible'),
|
||||
icon_url=dict(type='str', default='https://www.ansible.com/favicon.ico'),
|
||||
icon_emoji=dict(type='str', default=None),
|
||||
link_names=dict(type='int', default=1, choices=[0, 1]),
|
||||
validate_certs=dict(default='yes', type='bool'),
|
||||
color=dict(type='str', default='normal', choices=['normal', 'good', 'warning', 'danger']),
|
||||
attachments=dict(type='list', required=False, default=None)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -145,14 +145,14 @@ from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
||||
def post_sendgrid_api(module, username, password, from_address, to_addresses,
|
||||
subject, body, api_key=None, cc=None, bcc=None, attachments=None,
|
||||
html_body=False, from_name=None, headers=None):
|
||||
subject, body, api_key=None, cc=None, bcc=None, attachments=None,
|
||||
html_body=False, from_name=None, headers=None):
|
||||
|
||||
if not HAS_SENDGRID:
|
||||
SENDGRID_URI = "https://api.sendgrid.com/api/mail.send.json"
|
||||
AGENT = "Ansible"
|
||||
data = {'api_user': username, 'api_key':password,
|
||||
'from':from_address, 'subject': subject, 'text': body}
|
||||
data = {'api_user': username, 'api_key': password,
|
||||
'from': from_address, 'subject': subject, 'text': body}
|
||||
encoded_data = urlencode(data)
|
||||
to_addresses_api = ''
|
||||
for recipient in to_addresses:
|
||||
@@ -160,9 +160,9 @@ def post_sendgrid_api(module, username, password, from_address, to_addresses,
|
||||
to_addresses_api += '&to[]=%s' % recipient
|
||||
encoded_data += to_addresses_api
|
||||
|
||||
headers = { 'User-Agent': AGENT,
|
||||
'Content-type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json'}
|
||||
headers = {'User-Agent': AGENT,
|
||||
'Content-type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json'}
|
||||
return fetch_url(module, SENDGRID_URI, data=encoded_data, headers=headers, method='POST')
|
||||
else:
|
||||
|
||||
@@ -207,6 +207,7 @@ def post_sendgrid_api(module, username, password, from_address, to_addresses,
|
||||
# Main
|
||||
#
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
@@ -225,11 +226,11 @@ def main():
|
||||
attachments=dict(required=False, type='list')
|
||||
),
|
||||
supports_check_mode=True,
|
||||
mutually_exclusive = [
|
||||
mutually_exclusive=[
|
||||
['api_key', 'password'],
|
||||
['api_key', 'username']
|
||||
],
|
||||
required_together = [['username', 'password']],
|
||||
],
|
||||
required_together=[['username', 'password']],
|
||||
)
|
||||
|
||||
username = module.params['username']
|
||||
@@ -253,8 +254,8 @@ def main():
|
||||
'api_key, bcc, cc, headers, from_name, html_body, attachments')
|
||||
|
||||
response, info = post_sendgrid_api(module, username, password,
|
||||
from_address, to_addresses, subject, body, attachments=attachments,
|
||||
bcc=bcc, cc=cc, headers=headers, html_body=html_body, api_key=api_key)
|
||||
from_address, to_addresses, subject, body, attachments=attachments,
|
||||
bcc=bcc, cc=cc, headers=headers, html_body=html_body, api_key=api_key)
|
||||
|
||||
if not HAS_SENDGRID:
|
||||
if info['status'] != 200:
|
||||
|
||||
@@ -189,7 +189,7 @@ escape_table = {
|
||||
|
||||
def escape_quotes(text):
|
||||
'''Backslash any quotes within text.'''
|
||||
return "".join(escape_table.get(c,c) for c in text)
|
||||
return "".join(escape_table.get(c, c) for c in text)
|
||||
|
||||
|
||||
def build_payload_for_slack(module, text, channel, username, icon_url, icon_emoji, link_names, parse, color, attachments):
|
||||
@@ -203,7 +203,7 @@ def build_payload_for_slack(module, text, channel, username, icon_url, icon_emoj
|
||||
if (channel[0] == '#') or (channel[0] == '@'):
|
||||
payload['channel'] = channel
|
||||
else:
|
||||
payload['channel'] = '#'+channel
|
||||
payload['channel'] = '#' + channel
|
||||
if username is not None:
|
||||
payload['username'] = username
|
||||
if icon_emoji is not None:
|
||||
@@ -237,9 +237,10 @@ def build_payload_for_slack(module, text, channel, username, icon_url, icon_emoj
|
||||
|
||||
payload['attachments'].append(attachment)
|
||||
|
||||
payload=module.jsonify(payload)
|
||||
payload = module.jsonify(payload)
|
||||
return payload
|
||||
|
||||
|
||||
def do_notify_slack(module, domain, token, payload):
|
||||
if token.count('/') >= 2:
|
||||
# New style token
|
||||
@@ -259,21 +260,22 @@ def do_notify_slack(module, domain, token, payload):
|
||||
obscured_incoming_webhook = SLACK_INCOMING_WEBHOOK % ('[obscured]')
|
||||
module.fail_json(msg=" failed to send %s to %s: %s" % (payload, obscured_incoming_webhook, info['msg']))
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
domain = dict(type='str', required=False, default=None),
|
||||
token = dict(type='str', required=True, no_log=True),
|
||||
msg = dict(type='str', required=False, default=None),
|
||||
channel = dict(type='str', default=None),
|
||||
username = dict(type='str', default='Ansible'),
|
||||
icon_url = dict(type='str', default='https://www.ansible.com/favicon.ico'),
|
||||
icon_emoji = dict(type='str', default=None),
|
||||
link_names = dict(type='int', default=1, choices=[0,1]),
|
||||
parse = dict(type='str', default=None, choices=['none', 'full']),
|
||||
validate_certs = dict(default='yes', type='bool'),
|
||||
color = dict(type='str', default='normal', choices=['normal', 'good', 'warning', 'danger']),
|
||||
attachments = dict(type='list', required=False, default=None)
|
||||
argument_spec=dict(
|
||||
domain=dict(type='str', required=False, default=None),
|
||||
token=dict(type='str', required=True, no_log=True),
|
||||
msg=dict(type='str', required=False, default=None),
|
||||
channel=dict(type='str', default=None),
|
||||
username=dict(type='str', default='Ansible'),
|
||||
icon_url=dict(type='str', default='https://www.ansible.com/favicon.ico'),
|
||||
icon_emoji=dict(type='str', default=None),
|
||||
link_names=dict(type='int', default=1, choices=[0, 1]),
|
||||
parse=dict(type='str', default=None, choices=['none', 'full']),
|
||||
validate_certs=dict(default='yes', type='bool'),
|
||||
color=dict(type='str', default='normal', choices=['normal', 'good', 'warning', 'danger']),
|
||||
attachments=dict(type='list', required=False, default=None)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -112,15 +112,15 @@ def post_twilio_api(module, account_sid, auth_token, msg, from_number,
|
||||
% (account_sid,)
|
||||
AGENT = "Ansible"
|
||||
|
||||
data = {'From':from_number, 'To':to_number, 'Body':msg}
|
||||
data = {'From': from_number, 'To': to_number, 'Body': msg}
|
||||
if media_url:
|
||||
data['MediaUrl'] = media_url
|
||||
encoded_data = urlencode(data)
|
||||
|
||||
headers = {'User-Agent': AGENT,
|
||||
'Content-type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
'Content-type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
|
||||
# Hack module params to have the Basic auth params that fetch_url expects
|
||||
module.params['url_username'] = account_sid.replace('\n', '')
|
||||
@@ -159,7 +159,7 @@ def main():
|
||||
|
||||
for number in to_number:
|
||||
r, info = post_twilio_api(module, account_sid, auth_token, msg,
|
||||
from_number, number, media_url)
|
||||
from_number, number, media_url)
|
||||
if info['status'] not in [200, 201]:
|
||||
body_message = "unknown error"
|
||||
if 'body' in info:
|
||||
|
||||
Reference in New Issue
Block a user