ansible/ansible — pull request #5203 by sivel (2013-12-06 17:43:09+00:00)
Title: Improve IRC module. Fixes #5186

See #5186

Currently, the IRC module, opens a connection to the server, and starts sending commands. Some commands are separated with time.sleep() calls, but we should really be looking for responses from the IRC server to let us know when we can actually send commands.

As it is, on freenode, the "bot" never joins, and thus never sends the message. This is due to a sleep that is too short. Basically we need to connect, send NICK and USER, and wait for the server to respond with messages indicating success "registration" (not nick registration, but basically a response that you have successfully connected and can continue).

Additionally, we should wait after joining to ensure that we have actually joined a channel, before sending the string.

I did a bit of reading both on forums, existing IRC bots and RFC2812 and have something that currently works on the following IRC daemons:

ircd-seven (freenode)
InspIRCd

I haven't tested on many others due to lack of existing configurations.

The one problem with IRC servers is that while IRC has an RFC, the majority of the IRC servers do not follow it. So most IRC clients start with RFCs and then write edge cases to make it work for all networks.

I'd rather not write a full blown IRC client for ansible, since we cannot add a new dependency on a module that could break backwards compatibility, but we can try to make it work better.

Perhaps we can create a module in the future that supports IRC using an existing IRC python module to alleviate the issues, and allow the ansible module to be more flexible, but that is not necessarily my goal with this pull request.

Here is a test for the module:

```
$ ansible localhost -i "localhost," -c local -m irc -a "server=irc.freenode.net channel=#ansible msg=test"
localhost | success >> {
"changed": false,
"channel": "#ansible",
"msg": "test",
"nick": "ansible"
}
```