This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
new mcollective script for running mco commands from hubot #1419
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Description: | ||
# * Hubot interface to mcollective for puppet | ||
# * Currently able to start puppet runs and get status | ||
# of one server or collection of servers using an mco | ||
# regex filter | ||
# * Can also discover nodes using ping | ||
# | ||
# | ||
# Dependencies: | ||
# None | ||
# | ||
# Configuration: | ||
# HUBOT_PUPPET_MCOLLECTIVE_HOST - set this env variable to the hostname of your mcollective host | ||
# HUBOT_PUPPET_MCOLLECTIVE_CMD - set this env variable to the path to your mco executable on the mcollective host | ||
# | ||
# Commands: | ||
# mco ping: get list of hosts to run mco commands against | ||
# mco puppet run <target host> | ||
# mco puppet run <regex for group of hosts> | ||
# mco puppet status <target host> | ||
# mco puppet status <regex for group of hosts> | ||
# mco help | ||
# | ||
# Notes: | ||
# Requires root access (NOPASSWD) to the mcollective host | ||
# Feel free to modify for your environment and security constraints | ||
# | ||
# Author: | ||
# pzim <Phil Zimmerman> | ||
{spawn, exec} = require 'child_process' | ||
module.exports = (robot) -> | ||
|
||
|
||
mco_host = process.env.HUBOT_PUPPET_MCOLLECTIVE_HOST | ||
mco_cmd = process.env.HUBOT_PUPPET_MCOLLECTIVE_CMD | ||
mco_user = "peadmin" | ||
|
||
ssh_exec = (ssh_cmd, cb) -> | ||
child = exec ssh_cmd, (err, stdout, stderr) -> | ||
if !err | ||
result_text = stdout | ||
else | ||
result_text = stderr | ||
cb result_text | ||
|
||
robot.respond /mco ping/i, (msg) -> | ||
console.log("mco ping") | ||
|
||
exec "ssh -t root@#{mco_host} 'sudo -u #{mco_user} #{mco_cmd} ping'", (err, stdout, stderr) -> | ||
if err | ||
msg.send "failed to run mco: #{stderr}" | ||
else | ||
msg.send stdout | ||
|
||
robot.respond /mco puppet run (.*)/i, (msg) -> | ||
target_envs = msg.match[1] | ||
console.log("target_envs = #{target_envs}") | ||
|
||
ssh_string = "ssh -t root@#{mco_host} 'sudo -u #{mco_user} #{mco_cmd} puppet -v -j runonce -I #{target_envs}'" | ||
console.log ("#{ssh_string}") | ||
results = "" | ||
ssh_exec ssh_string, (output) -> | ||
responses = JSON.parse(output) | ||
for item in responses | ||
host = item.sender | ||
console.log("host = #{host}") | ||
status = item.data.summary | ||
console.log("status = #{status}") | ||
tmpout = "host: #{host}, result: #{status}\n" | ||
results = results + tmpout | ||
msg.send results | ||
|
||
|
||
robot.respond /mco puppet status (.*)/i, (msg) -> | ||
target_envs = msg.match[1] | ||
console.log("target_envs = #{target_envs}") | ||
|
||
ssh_string = "ssh -t root@#{mco_host} 'sudo -u #{mco_user} #{mco_cmd} puppet -j -I #{target_envs} status'" | ||
console.log ("#{ssh_string}") | ||
ssh_exec ssh_string, (output) -> | ||
msg.send output | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth making this configurable, but with a default of peadmin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally getting back to this - yes, good catch - that should totally be
configurable.
On Thu, Apr 24, 2014 at 10:08 AM, Josh Nichols notifications@github.comwrote: