Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
08c9b669
Commit
08c9b669
authored
May 08, 2013
by
Jan-Piet Mens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new module: IRC notification
parent
e075607c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
0 deletions
+146
-0
library/notification/irc
+146
-0
No files found.
library/notification/irc
0 → 100644
View file @
08c9b669
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# (c) 2013, Jan-Piet Mens <jpmens () gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
DOCUMENTATION
=
'''
---
module: irc
short_description: Send a message to an IRC channel
description:
- Send a message to an IRC channel. This is a very simplistic implementation.
options:
server:
description:
- IRC server name/address
required: false
default: localhost
port:
description:
- IRC server port number
required: false
default: 6667
nick:
description:
- Nickname
required: false
default: ansible
msg:
description:
- The message body.
required: true
default: null
color:
description:
- Text color for the message. Default is black.
required: false
default: black
choices: [ "yellow", "red", "green", "blue", "black" ]
channel:
description:
- Channel name
required: true
# informational: requirements for nodes
requirements: [ socket ]
author: Jan-Piet Mens
'''
EXAMPLES
=
'''
action: irc server=irc.example.net channel="#t1" msg="Hello world"
local_action: irc port=6669
channel="#t1"
msg="Hello at {{ ansible_date_time.iso8601 }}"
color=red
nick=ansibleIRC
'''
# ===========================================
# IRC module support methods.
#
import
socket
def
send_msg
(
channel
,
msg
,
server
=
'localhost'
,
port
=
'6667'
,
nick
=
"ansible"
,
color
=
'black'
):
'''send message to IRC'''
colornumbers
=
{
'black'
:
"01"
,
'red'
:
"04"
,
'green'
:
"09"
,
'yellow'
:
"08"
,
'blue'
:
"12"
,
}
try
:
colornumber
=
colornumbers
[
color
]
except
:
colornumber
=
"01"
# black
message
=
"
\x03
"
+
colornumber
+
msg
irc
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
irc
.
connect
(
(
server
,
int
(
port
)
)
)
irc
.
send
(
'NICK
%
s
\r\n
'
%
nick
)
irc
.
send
(
'USER
%
s
%
s
%
s :ansible IRC
\r\n
'
%
(
nick
,
nick
,
nick
))
irc
.
send
(
'JOIN #
%
s
\r\n
'
%
channel
)
irc
.
send
(
'PRIVMSG
%
s :
%
s
\r\n
'
%
(
channel
,
message
))
irc
.
send
(
'PART
%
s
\r\n
'
%
channel
)
irc
.
send
(
'QUIT
\r\n
'
)
irc
.
close
()
# ===========================================
# Main
#
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
server
=
dict
(
default
=
'localhost'
),
port
=
dict
(
default
=
6667
),
nick
=
dict
(
default
=
'ansible'
),
msg
=
dict
(
required
=
True
),
color
=
dict
(
default
=
"black"
,
choices
=
[
"yellow"
,
"red"
,
"green"
,
"blue"
,
"black"
]),
channel
=
dict
(
required
=
True
)
),
supports_check_mode
=
True
)
server
=
module
.
params
[
"server"
]
port
=
module
.
params
[
"port"
]
nick
=
module
.
params
[
"nick"
]
msg
=
module
.
params
[
"msg"
]
color
=
module
.
params
[
"color"
]
channel
=
module
.
params
[
"channel"
]
try
:
send_msg
(
channel
,
msg
,
server
,
port
,
nick
,
color
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"unable to send to IRC:
%
s"
%
e
)
changed
=
True
module
.
exit_json
(
changed
=
changed
,
channel
=
channel
,
nick
=
nick
,
msg
=
msg
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment