remote_executor 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +45 -4
- data/bin/remote_executor +1 -1
- data/lib/remote_executor.rb +3 -3
- data/lib/remote_executor/cli.rb +15 -6
- data/lib/remote_executor/config.rb +2 -6
- data/lib/remote_executor/system_config.rb +28 -0
- data/lib/remote_executor/version.rb +1 -1
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
= Remote Executor:
|
1
|
+
= Remote Executor:
|
2
|
+
|
3
|
+
A simplistic remote command launcher over SSH conections
|
2
4
|
|
3
5
|
== Installing
|
4
6
|
|
@@ -7,18 +9,57 @@ The latest stable version is published in gemcutter.
|
|
7
9
|
gem source --add http://gemcutter.org
|
8
10
|
gem install remote_executor
|
9
11
|
|
10
|
-
|
11
12
|
== Notes
|
12
13
|
|
13
14
|
At the moment the gem have a strong dependency of your local SSH configuration, commonly located at ${HOME}/.ssh/config, this is only a
|
14
15
|
very simple mechanism for keep safe your private data, but this need a ugly configuration with a fake user name in the connection
|
15
16
|
process. I provide a basic SSH config if your aren´t familiar with this configuration stuff
|
16
17
|
|
18
|
+
=== How to use
|
19
|
+
|
20
|
+
An example may be the next. Launch the command 'hostname' over your production farm system named 'myFarm' configured in your home
|
21
|
+
directory into the file ${HOME}/.remoteexecutorrc like this:
|
22
|
+
|
23
|
+
---
|
24
|
+
:production:
|
25
|
+
- :name: 'myFarm'
|
26
|
+
:hosts:
|
27
|
+
- 'myHost1'
|
28
|
+
- 'myHost2'
|
29
|
+
- 'myHost3'
|
30
|
+
- 'myHost4'
|
31
|
+
|
32
|
+
you need this minimal SSH configuration (${HOME}/.ssh/config) for the example
|
33
|
+
|
34
|
+
Host myHost1
|
35
|
+
HostName myhost1.example.com
|
36
|
+
Host myHost2
|
37
|
+
HostName myhost2.example.com
|
38
|
+
Host myHost3
|
39
|
+
HostName myhost3.example.com
|
40
|
+
Host myHost4
|
41
|
+
HostName myhost4.example.com
|
42
|
+
|
43
|
+
*.example.com
|
44
|
+
User admin
|
45
|
+
|
46
|
+
with this line:
|
47
|
+
|
48
|
+
remote_executor --system=myFarm --environment=production --command='hostname'
|
49
|
+
|
50
|
+
=== Configuration
|
51
|
+
|
52
|
+
The configuration for this gem is divided in 3 levels
|
17
53
|
|
54
|
+
* Via --config command option
|
55
|
+
* Via your shell environment with the variable REMOTEEXECUTOR (export REMOTEEXECUTOR="${HOME}/configs/remote_executor_settins.yml")
|
56
|
+
* Via your user preferences located in the ${HOME}/.remoteexecutorrc file
|
57
|
+
|
18
58
|
== TODO
|
19
59
|
|
20
|
-
* Document all stuff in english... I promise
|
21
|
-
* Write some test
|
60
|
+
* Document all this stuff in english... I promise
|
61
|
+
* Write some test could be a gread idea xD
|
62
|
+
* Pullrequests are welcome... of course
|
22
63
|
|
23
64
|
== License
|
24
65
|
|
data/bin/remote_executor
CHANGED
data/lib/remote_executor.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
begin
|
2
2
|
%w[rubygems yaml singleton choice net/ssh].each { |gem| require gem }
|
3
3
|
rescue LoadError => e
|
4
|
-
fail "Some gem dependencies can
|
4
|
+
fail "Some gem dependencies can not be loaded: #{e.message}"
|
5
5
|
end
|
6
6
|
|
7
7
|
$:.unshift File.join( File.dirname( __FILE__), 'remote_executor' )
|
8
8
|
|
9
9
|
begin
|
10
|
-
%w[version config options_parser cli].each { |lib| require lib }
|
10
|
+
%w[version config system_config options_parser cli].each { |lib| require lib }
|
11
11
|
rescue LoadError => e
|
12
|
-
fail "Some lib dependencies can
|
12
|
+
fail "Some lib dependencies can not be loaded: #{e.message}"
|
13
13
|
end
|
data/lib/remote_executor/cli.rb
CHANGED
@@ -1,13 +1,22 @@
|
|
1
1
|
module RemoteExecutor
|
2
|
+
|
3
|
+
class BadEnvironment < Exception
|
4
|
+
end
|
5
|
+
|
2
6
|
class Cli
|
3
7
|
|
4
|
-
def self.execute(
|
5
|
-
|
6
|
-
Config.instance[environment].each do |system|
|
8
|
+
def self.execute( name, environment, command )
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
system_target = SystemConfig.instance.find_system( name )
|
11
|
+
|
12
|
+
if( system_target[:environment].to_sym == environment.to_sym )
|
13
|
+
|
14
|
+
system_target[:hosts].each do |host|
|
15
|
+
|
16
|
+
Net::SSH.start( host, system_target[:user], :config=>true ) { |ssh_session| ssh_session.exec( "#{command}" ) }
|
17
|
+
end
|
18
|
+
else
|
19
|
+
raise BadEnvironment.new( "Bad environment..." )
|
11
20
|
end
|
12
21
|
end
|
13
22
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module RemoteExecutor
|
2
|
+
|
2
3
|
class YAMLFileNotFound < Exception
|
3
4
|
end
|
4
5
|
|
5
6
|
class Config
|
6
|
-
include Singleton
|
7
7
|
|
8
8
|
##
|
9
9
|
# Get the default configuration over Choice, environment and user default settings
|
@@ -24,10 +24,6 @@ module RemoteExecutor
|
|
24
24
|
@config = YAML.load_file( Config.get_config_file( CLIApplication::NAME ) )
|
25
25
|
rescue Exception => e
|
26
26
|
raise YAMLFileNotFound.new( e.message )
|
27
|
-
end
|
28
|
-
|
29
|
-
def [](key)
|
30
|
-
@config[key.to_sym] if @config
|
31
|
-
end
|
27
|
+
end
|
32
28
|
end
|
33
29
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RemoteExecutor
|
2
|
+
|
3
|
+
class ConfigurationError < Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
class SystemConfig < Config
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def find_system( system_name )
|
10
|
+
|
11
|
+
@config.each { |s| return s if( s[:name] == system_name) }
|
12
|
+
|
13
|
+
raise ConfigurationError.new( "System #{system_name} not found" )
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_environment( system_name )
|
17
|
+
@config.each { |s| return s[:environment].to_sym if( s[:name] == system_name) }
|
18
|
+
|
19
|
+
raise ConfigurationError.new( "The system #{system_name} do not have declared environment" )
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_hosts( system_name )
|
23
|
+
@config.each { |s| return s[:hosts] if( s[:name] == system_name) }
|
24
|
+
|
25
|
+
raise ConfigurationError.new( "The system #{system_name} do not have host lists, WTF!!!" )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remote_executor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Javier Juarez
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/remote_executor/cli.rb
|
61
61
|
- lib/remote_executor/config.rb
|
62
62
|
- lib/remote_executor/options_parser.rb
|
63
|
+
- lib/remote_executor/system_config.rb
|
63
64
|
- lib/remote_executor/version.rb
|
64
65
|
- README.rdoc
|
65
66
|
has_rdoc: true
|