Implemented comments

pull/18777/head
Adrian Muraru 9 years ago committed by Matt Clay
parent 6052b718e1
commit 586aacbd84

@ -39,7 +39,7 @@ options:
default: 6667 default: 6667
nick: nick:
description: description:
- Nickname. May be shortened, depending on server's NICKLEN setting. - Nickname to send the message from. May be shortened, depending on server's NICKLEN setting.
required: false required: false
default: ansible default: ansible
msg: msg:
@ -65,8 +65,9 @@ options:
required: true required: true
nick_to: nick_to:
description: description:
- Nick to send the message to - A list of nicknames to send the message to. When both channel and nick_to are defined, the message will be send to both of them.
required: false required: false
version_added: 2.0
key: key:
description: description:
- Channel key - Channel key
@ -99,7 +100,16 @@ EXAMPLES = '''
- irc: server=irc.example.net channel="#t1" msg="Hello world" - irc: server=irc.example.net channel="#t1" msg="Hello world"
- local_action: irc port=6669 - local_action: irc port=6669
server="irc.example.net"
channel="#t1"
msg="All finished at {{ ansible_date_time.iso8601 }}"
color=red
nick=ansibleIRC
- local_action: irc port=6669
server="irc.example.net"
channel="#t1" channel="#t1"
nick_to=["nick1", "nick2"]
msg="All finished at {{ ansible_date_time.iso8601 }}" msg="All finished at {{ ansible_date_time.iso8601 }}"
color=red color=red
nick=ansibleIRC nick=ansibleIRC
@ -116,8 +126,8 @@ import ssl
from time import sleep from time import sleep
def send_msg(channel, msg, server='localhost', port='6667', key=None, topic=None, def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=[], key=None, topic=None,
nick="ansible", nick_to=None, color='none', passwd=False, timeout=30, use_ssl=False): nick="ansible", color='none', passwd=False, timeout=30, use_ssl=False):
'''send message to IRC''' '''send message to IRC'''
colornumbers = { colornumbers = {
@ -178,8 +188,9 @@ def send_msg(channel, msg, server='localhost', port='6667', key=None, topic=None
sleep(1) sleep(1)
if nick_to: if nick_to:
irc.send('PRIVMSG %s :%s\r\n' % (nick_to, message)) for nick in nick_to:
else: irc.send('PRIVMSG %s :%s\r\n' % (nick, message))
if channel:
irc.send('PRIVMSG %s :%s\r\n' % (channel, message)) irc.send('PRIVMSG %s :%s\r\n' % (channel, message))
sleep(1) sleep(1)
irc.send('PART %s\r\n' % channel) irc.send('PART %s\r\n' % channel)
@ -198,35 +209,38 @@ def main():
server=dict(default='localhost'), server=dict(default='localhost'),
port=dict(default=6667), port=dict(default=6667),
nick=dict(default='ansible'), nick=dict(default='ansible'),
nick_to=dict(), nick_to=dict(required=False, type='list'),
msg=dict(required=True), msg=dict(required=True),
color=dict(default="none", choices=["yellow", "red", "green", color=dict(default="none", choices=["yellow", "red", "green",
"blue", "black", "none"]), "blue", "black", "none"]),
channel=dict(required=True), channel=dict(required=False),
key=dict(), key=dict(),
topic=dict(), topic=dict(),
passwd=dict(), passwd=dict(),
timeout=dict(type='int', default=30), timeout=dict(type='int', default=30),
use_ssl=dict(type='bool', default=False) use_ssl=dict(type='bool', default=False)
), ),
supports_check_mode=True supports_check_mode=True,
required_one_of=[['channel', 'nick_to']]
) )
server = module.params["server"] server = module.params["server"]
port = module.params["port"] port = module.params["port"]
nick = module.params["nick"] nick = module.params["nick"]
topic = module.params["topic"]
nick_to = module.params["nick_to"] nick_to = module.params["nick_to"]
msg = module.params["msg"] msg = module.params["msg"]
color = module.params["color"] color = module.params["color"]
channel = module.params["channel"] channel = module.params["channel"]
topic = module.params["topic"]
if topic and not channel:
module.fail_json(msg="When topic is specified, a channel is required.")
key = module.params["key"] key = module.params["key"]
passwd = module.params["passwd"] passwd = module.params["passwd"]
timeout = module.params["timeout"] timeout = module.params["timeout"]
use_ssl = module.params["use_ssl"] use_ssl = module.params["use_ssl"]
try: try:
send_msg(channel, msg, server, port, key, topic, nick, nick_to, color, passwd, timeout, use_ssl) send_msg(msg, server, port, channel, nick_to, key, topic, nick, color, passwd, timeout, use_ssl)
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)

Loading…
Cancel
Save