From f70e31257da95784ccdf3345846188782a1f5688 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Fri, 8 Aug 2014 14:08:12 -0700 Subject: [PATCH 1/2] Added SSL support for IRC --- library/notification/irc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/library/notification/irc b/library/notification/irc index b6b05f9be9b..ee673966008 100644 --- a/library/notification/irc +++ b/library/notification/irc @@ -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) From 535fb7345ac2ca7fe4d54ca8388cb3c8b5e6b9e0 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 8 Aug 2014 19:43:20 -0500 Subject: [PATCH 2/2] Bumping version_added for use_ssl param in irc module --- library/notification/irc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/notification/irc b/library/notification/irc index ee673966008..a90834f820d 100644 --- a/library/notification/irc +++ b/library/notification/irc @@ -76,7 +76,7 @@ options: description: - Designates whether TLS/SSL should be used when connecting to the IRC server default: False - version_added: 1.7 + version_added: 1.8 # informational: requirements for nodes requirements: [ socket ]