Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (55 sloc) 2.093 kB
# Allows hubot to run commands using chef.
#
# list nodes - Lists all nodes on Opscode
# uptime <server> - Prints uptime
# configure <server> - Runs chef client on node
module.exports = (robot) ->
robot.respond /list nodes$/i, (msg) ->
spawn = require('child_process').spawn
server = msg.match[1]
command = "knife node list"
msg.send "Listing nodes ..."
@exec = require('child_process').exec
@exec command, (error, stdout, stderr) ->
msg.send error
msg.send stdout
msg.send stderr
robot.respond /knife (node|role|client) show (.*)$/i, (msg) ->
spawn = require('child_process').spawn
subcmd = msg.match[1]
name = msg.match[2]
command = "knife #{subcmd} show #{name}"
msg.send "Running: #{command}"
@exec = require('child_process').exec
@exec command, (error, stdout, stderr) ->
msg.send error
msg.send stdout
msg.send stderr
robot.respond /uptime (.*)$/i, (msg) ->
spawn = require('child_process').spawn
server = msg.match[1]
command = "knife ssh --ssh-user root name:#{server} 'uptime'"
msg.send "Checking #{server} for uptime ..."
@exec = require('child_process').exec
@exec command, (error, stdout, stderr) ->
msg.send error
msg.send stdout
msg.send stderr
robot.respond /configure (.*)$/i, (msg) ->
server = msg.match[1]
@exec = require('child_process').exec
command = "knife ssh --ssh-user root --attribute ipaddress --no-color name:#{server} 'sudo chef-client'"
msg.send "Configuring #{server}."
@exec command, (error, stdout, stderr) ->
msg.send error
msg.send stdout
msg.send stderr
robot.respond /configure-environment (.*)$/i, (msg) ->
environment = msg.match[1]
@exec = require('child_process').exec
command = "knife ssh --ssh-user root --no-color --attribute ipaddress chef_environment:#{environment} 'sudo chef-client'"
msg.send "Configuring #{environment}."
@exec command, (error, stdout, stderr) ->
msg.send error
msg.send stdout
msg.send stderr
Jump to Line
Something went wrong with that request. Please try again.