-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
205 additions
and
41 deletions.
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
/tmp | ||
.env | ||
mastermind.wiki | ||
examples |
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
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
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
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
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 |
---|---|---|
@@ -1,11 +1,2 @@ | ||
## Definitions | ||
|
||
* definition names are based on their file names. | ||
* example definition: (no more `Mastermind.define do`) | ||
|
||
|
||
* defs are read in from the filesystem and parsed by the Mastermind::Reader | ||
|
||
|
||
!! OR !! | ||
# Allow specifying of a custom key in which to hold participant results. | ||
|
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,21 @@ | ||
require 'spice' | ||
|
||
module Participant::CM | ||
class Chef < Participant | ||
|
||
# Not a real participant. Just a base class to inherit from. | ||
|
||
option :server_url, ENV['CHEF_SERVER_URL'] | ||
option :client_name, ENV['CHEF_CLIENT_NAME'] | ||
option :client_key, Spice.read_key_file(File.expand_path(ENV['CHEF_CLIENT_KEY'])) | ||
|
||
def connection | ||
Spice::Connection.new( | ||
server_url: options[:server_url], | ||
client_name: options[:client_name], | ||
client_key: options[:client_key] | ||
) | ||
end | ||
|
||
end | ||
end |
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,19 @@ | ||
require 'spice' | ||
require Rails.root + 'app/participants/cm/chef' | ||
|
||
module Participant::CM | ||
class Chef::Node < Chef | ||
option :server_url, ENV['CHEF_SERVER_URL'] | ||
option :client_name, ENV['CHEF_CLIENT_NAME'] | ||
option :client_key, Spice.read_key_file(File.expand_path(ENV['CHEF_CLIENT_KEY'])) | ||
|
||
register :chef_node | ||
|
||
action :list do | ||
chef_nodes = connection.get('/nodes').keys | ||
|
||
{ chef_nodes: chef_nodes } | ||
end | ||
|
||
end | ||
end |
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,72 @@ | ||
require 'net/ssh' | ||
|
||
module Participant::Remote | ||
class SSHMulti < Participant | ||
register :ssh_multi | ||
|
||
action :run do | ||
requires :hosts, :user, :key_data, :command | ||
|
||
output = run_ssh(target.command) | ||
|
||
{ output: output } | ||
end | ||
|
||
|
||
def run_ssh(command) | ||
output = {} | ||
|
||
session = Net::SSH::Multi.start() | ||
|
||
opts = {} | ||
opts[:user] = target.user | ||
opts[:key_data] = [target.key_data] | ||
|
||
target.hosts.each do |host| | ||
session.use(host, opts) | ||
end | ||
|
||
session.open_channel do |ch| | ||
ch.request_pty | ||
ch.exec command do |ch, success| | ||
raise ArgumentError, "Cannot execute #{command}" unless success | ||
ch.on_data do |ichannel, data| | ||
output[ichannel[:host]] = data | ||
end | ||
end | ||
end | ||
|
||
session.loop | ||
session.close | ||
return output if output | ||
end | ||
|
||
def tcp_test_ssh(hostname) | ||
tcp_socket = TCPSocket.new(hostname, 22) | ||
readable = IO.select([tcp_socket], nil, nil, 5) | ||
if readable | ||
Mastermind.logger.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}") | ||
yield | ||
true | ||
else | ||
false | ||
end | ||
rescue SocketError | ||
sleep 2 | ||
false | ||
rescue Errno::ETIMEDOUT | ||
false | ||
rescue Errno::EPERM | ||
false | ||
rescue Errno::ECONNREFUSED | ||
sleep 2 | ||
false | ||
# This happens on EC2 quite often | ||
rescue Errno::EHOSTUNREACH | ||
sleep 2 | ||
false | ||
ensure | ||
tcp_socket && tcp_socket.close | ||
end | ||
end | ||
end |
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
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,7 @@ | ||
module Target::CM | ||
class Chef < Target | ||
|
||
# not a real target | ||
|
||
end | ||
end |
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,18 @@ | ||
require Rails.root + 'app/targets/cm/chef' | ||
|
||
module Target::CM | ||
class Chef::Node < Target | ||
register :chef_node | ||
|
||
attribute :name, type: String | ||
attribute :run_list, type: Object, default: [] | ||
attribute :automatic, type: Object, default: {} | ||
attribute :default, type: Object, default: {} | ||
attribute :normal, type: Object, default: {} | ||
attribute :override, type: Object, default: {} | ||
attribute :_rev, type: String | ||
attribute :chef_type, type: String, default: "node" | ||
attribute :json_class, type: String, default: "Chef::Node" | ||
|
||
end | ||
end |
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,14 @@ | ||
module Target::Remote | ||
class SSHMulti < Target | ||
register :ssh_multi | ||
|
||
attribute :command, type: String | ||
attribute :hosts, type: Object | ||
attribute :user, type: String | ||
attribute :key_data, type: String | ||
attribute :output, type: String | ||
|
||
validates! :command, :hosts, :user, :key_data, | ||
presence: true | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.