Merge pull request #3347 from AscendLearning/irc-with-pass

Added a provision for passing a server password to IRC
This commit is contained in:
Michael DeHaan 2013-06-30 09:17:19 -07:00
commit 71b9be509c

View file

@ -56,6 +56,10 @@ options:
description: description:
- Channel name - Channel name
required: true required: true
passwd:
description:
- Server password
required: false
# informational: requirements for nodes # informational: requirements for nodes
requirements: [ socket ] requirements: [ socket ]
@ -80,7 +84,7 @@ from time import sleep
import socket import socket
def send_msg(channel, msg, server='localhost', port='6667', def send_msg(channel, msg, server='localhost', port='6667',
nick="ansible", color='black'): nick="ansible", color='black', passwd=False):
'''send message to IRC''' '''send message to IRC'''
colornumbers = { colornumbers = {
@ -100,6 +104,8 @@ def send_msg(channel, msg, server='localhost', port='6667',
irc = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) irc = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
irc.connect( ( server, int(port) ) ) irc.connect( ( server, int(port) ) )
if passwd:
irc.send( 'PASS %s\r\n' % passwd )
irc.send( 'NICK %s\r\n' % nick ) irc.send( 'NICK %s\r\n' % nick )
irc.send( 'USER %s %s %s :ansible IRC\r\n' % (nick, nick, nick)) irc.send( 'USER %s %s %s :ansible IRC\r\n' % (nick, nick, nick))
time.sleep(1) time.sleep(1)
@ -125,7 +131,8 @@ def main():
msg = dict(required = True), msg = dict(required = True),
color = dict(default="black", choices=["yellow", "red", "green", color = dict(default="black", choices=["yellow", "red", "green",
"blue", "black"]), "blue", "black"]),
channel = dict(required = True) channel = dict(required = True),
passwd = dict()
), ),
supports_check_mode=True supports_check_mode=True
) )
@ -136,9 +143,10 @@ def main():
msg = module.params["msg"] msg = module.params["msg"]
color = module.params["color"] color = module.params["color"]
channel = module.params["channel"] channel = module.params["channel"]
passwd = module.params["passwd"]
try: try:
send_msg(channel, msg, server, port, nick, color) send_msg(channel, msg, server, port, nick, color, passwd)
except Exception, e: except Exception, e:
module.fail_json(msg="unable to send to IRC: %s" % e) module.fail_json(msg="unable to send to IRC: %s" % e)