Merge branch 'ah/add_ssl_for_irc' of https://github.com/ahamilton55/ansible into ahamilton55-ah/add_ssl_for_irc

This commit is contained in:
James Cammarata 2014-08-08 19:39:46 -05:00
commit 29b0fd6829

View file

@ -72,6 +72,11 @@ options:
messages, this is to prevent an endless loop
default: 30
version_added: 1.5
use_ssl:
description:
- Designates whether TLS/SSL should be used when connecting to the IRC server
default: False
version_added: 1.7
# informational: requirements for nodes
requirements: [ socket ]
@ -94,12 +99,13 @@ EXAMPLES = '''
import re
import socket
import ssl
from time import sleep
def send_msg(channel, msg, server='localhost', port='6667', key=None,
nick="ansible", color='none', passwd=False, timeout=30):
nick="ansible", color='none', passwd=False, timeout=30, use_ssl=False):
'''send message to IRC'''
colornumbers = {
@ -119,6 +125,8 @@ def send_msg(channel, msg, server='localhost', port='6667', key=None,
message = colortext + msg
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if use_ssl:
irc = ssl.wrap_socket(irc)
irc.connect((server, int(port)))
if passwd:
irc.send('PASS %s\r\n' % passwd)
@ -177,7 +185,8 @@ def main():
channel=dict(required=True),
key=dict(),
passwd=dict(),
timeout=dict(type='int', default=30)
timeout=dict(type='int', default=30),
use_ssl=dict(type='bool', default=False)
),
supports_check_mode=True
)
@ -191,9 +200,10 @@ def main():
key = module.params["key"]
passwd = module.params["passwd"]
timeout = module.params["timeout"]
use_ssl = module.params["use_ssl"]
try:
send_msg(channel, msg, server, port, key, nick, color, passwd, timeout)
send_msg(channel, msg, server, port, key, nick, color, passwd, timeout, use_ssl)
except Exception, e:
module.fail_json(msg="unable to send to IRC: %s" % e)