Skip to content

Instantly share code, notes, and snippets.

@shirou
Created September 22, 2014 16:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shirou/978aac75b6ea2d09257d to your computer and use it in GitHub Desktop.
Save shirou/978aac75b6ea2d09257d to your computer and use it in GitHub Desktop.
ansible + hubot + slack integration
settings = {
'test': {
'path': '/home/shirou/ansible/test/',
'inventory': 'inventory'
}
}
module.exports = (robot) ->
robot.respond /ansible (.*) (.*)$/i, (msg) ->
target="test" # should be comes from channel
playbook = msg.match[1]
limit = msg.match[2]
@exec = require('child_process').exec
msg.send "doing: #{target} #{playbook} to #{limit}"
cwd = settings[target]['path']
invfile = settings[target]['inventory']
command = "/usr/local/bin/ansible-playbook -i #{invfile} #{playbook} -l #{limit}"
@exec command, {cwd: cwd}, (error, stdout, stderr) ->
msg.send stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment