Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

new mcollective script for running mco commands from hubot #1419

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/scripts/mcollective.coffee
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"
Copy link
Contributor

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?

Copy link
Author

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:

In src/scripts/mcollective.coffee:

+# mco puppet status
+# mco help
+#
+# Notes:
+# Requires root access (NOPASSWD) to the mcollective host
+# Feel free to modify for your environment and security constraints
+#
+# Author:
+# pzim
+{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"

Would it be worth making this configurable, but with a default of peadmin?


Reply to this email directly or view it on GitHubhttps://github.com//pull/1419/files#r11956506
.


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