Created
September 22, 2014 16:10
-
-
Save shirou/978aac75b6ea2d09257d to your computer and use it in GitHub Desktop.
ansible + hubot + slack integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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