paratele 0.0.3 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,10 +1,10 @@
1
1
  TELE(1)
2
2
 
3
3
  NAME
4
- tele -- Provisioning at a distance.
4
+ paratele -- Provisioning at a distance.
5
5
 
6
6
  SYNOPSIS
7
- tele [-h] [-d path] (init|status|install)
7
+ paratele [-h] [-d path] (init|run)
8
8
 
9
9
  DESCRIPTION
10
10
  Tele is a small provisioning framework that allows you to run bash
@@ -99,8 +99,11 @@ USAGE
99
99
  Host server2
100
100
  Hostname 10.0.0.2
101
101
 
102
- # Run tele install
103
- $ tele run install
102
+ # Run the install script for all recipes
103
+ $ paratele run install
104
+
105
+ # Run the deploy script for certain servers
106
+ $ paratele run deploy web1,db1
104
107
 
105
108
  INSTALLATION
106
- $ gem install tele
109
+ $ gem install paratele
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
+ task :default => :test
2
+
1
3
  task :test do
2
4
  require "cutest"
3
-
4
5
  Cutest.run(Dir["test/tele.rb"])
5
6
  end
6
-
7
- task :default => :test
data/bin/paratele CHANGED
@@ -1,42 +1,62 @@
1
- #! /usr/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
- help = File.expand_path(File.join("..", "README"), File.dirname(__FILE__))
4
-
5
- if ARGV.empty?
6
- exec "less #{help}"
7
- end
8
-
9
- require "clap"
10
3
  require "json"
11
4
  require "open3"
5
+ require "clap"
6
+ require "erb"
12
7
 
13
- def path(*parts)
14
- File.expand_path(File.join(*parts), ENV["TELE_HOME"])
8
+ $verbosity = 1
9
+ $home = Dir.pwd
10
+
11
+ class Template
12
+ attr_accessor :attributes
13
+
14
+ def initialize source
15
+ @source = source
16
+ end
17
+
18
+ def render
19
+ ERB.new(@source).result(binding)
20
+ end
15
21
  end
16
22
 
17
- def ssh(server, script)
18
- out, status = Open3.capture2e("ssh -T -F #{path("ssh_config")} #{server} < #{script}")
19
- [out, status.exitstatus]
23
+ def path *parts
24
+ File.join($home, *parts)
20
25
  end
21
26
 
22
27
  def layout
23
- $layout ||= JSON.parse(File.read(path("layout.json")))
28
+ @layout ||= JSON.parse(File.read(path("layout.json")))
24
29
  end
25
30
 
26
- def servers
27
- layout["servers"]
31
+ def run server, recipe, command, attributes={}
32
+ template_path = path("recipes", recipe, "#{command}.erb")
33
+ if File.exists?(template_path)
34
+ source = File.read(template_path)
35
+ template = Template.new(source)
36
+ template.attributes = attributes
37
+ ssh(server, template.render)
38
+ end
28
39
  end
29
40
 
30
- def recipe_script(recipe, command)
31
- path("recipes", recipe, "#{command}.sh")
41
+ def ssh server, script
42
+ out, status = Open3.capture2e("ssh -T -F #{path("ssh_config")} #{server}", :stdin_data => script)
43
+ [out, status.exitstatus]
32
44
  end
33
45
 
34
- def run(server, recipe, command)
35
- script = recipe_script(recipe, command)
46
+ commands = Clap.run ARGV,
47
+ "-q" => lambda {
48
+ $verbosity = 0
49
+ },
50
+ "-v" => lambda {
51
+ $verbosity = 2
52
+ },
53
+ "-d" => lambda {|path|
54
+ $home = File.join(Dir.pwd, path)
55
+ }
36
56
 
37
- if File.exist?(script)
38
- ssh(server, script)
39
- end
57
+ unless File.exists?(path("layout.json"))
58
+ $stderr.puts "Couldn't find `layout.json`"
59
+ exit 1
40
60
  end
41
61
 
42
62
  out = Module.new do
@@ -65,76 +85,49 @@ out = Module.new do
65
85
  end
66
86
  end
67
87
 
68
- ###
69
-
70
- ENV["TELE_HOME"] ||= File.join(Dir.pwd, ".tele")
88
+ case ARGV.shift
89
+ when "run" then
90
+ command = ARGV.shift
91
+ environment, servers = ARGV.shift.split(":")
71
92
 
72
- verbosity = 1
93
+ environment = layout[environment]
94
+ servers = if servers
95
+ servers.split(",")
96
+ else
97
+ environment["servers"].keys
98
+ end
73
99
 
74
- commands = Clap.run ARGV,
75
- "-h" => lambda {
76
- exec "less #{help}"
77
- },
78
- "-q" => lambda {
79
- verbosity = 0
80
- },
81
- "-v" => lambda {
82
- verbosity = 2
83
- },
84
- "-d" => lambda {|path|
85
- ENV["TELE_HOME"] = File.join(Dir.pwd, path)
86
- }
100
+ exit_status = 0
87
101
 
88
- Clap.run commands,
89
- "init" => lambda {
90
- source = File.expand_path("../templates/.tele", File.dirname(__FILE__))
91
- target = File.expand_path(Dir.pwd)
102
+ servers.each do |server|
103
+ recipes = environment["servers"][server]
92
104
 
93
- %x{cp -r #{source} #{target}}
94
- out.done
95
- }
105
+ out.server(server)
96
106
 
97
- unless File.directory?(path)
98
- $stderr.puts "Couldn't find a .tele directory"
99
- exit 1
100
- end
107
+ recipes.each do |recipe|
108
+ print " #{recipe}: "
101
109
 
102
- Clap.run commands,
103
- "run" => lambda {|command|
104
- if commands.size == 3
105
- selected = commands.last.split(",")
106
- servers.select! {|server| selected.include?(server)}
107
- end
110
+ if File.exists?(path("recipes", recipe))
111
+ stdout, status = run(server, recipe, command, environment["attributes"])
108
112
 
109
- exit_status = 0
110
-
111
- servers.each do |server, recipes|
112
- out.server(server)
113
-
114
- recipes.each do |recipe|
115
- print " #{recipe}: "
116
-
117
- if File.exists?(path("recipes", recipe))
118
- stdout, status = run(server, recipe, command)
119
-
120
- case status
121
- when nil
122
- out.unknown
123
- when 0
124
- out.ok
125
- $stderr.print stdout if verbosity >= 2
126
- else
127
- out.error
128
- $stderr.print stdout if verbosity >= 1
129
- exit_status = 1
130
- break
131
- end
132
- else
113
+ case status
114
+ when nil
133
115
  out.unknown
134
- exit 1
116
+ when 0
117
+ out.ok
118
+ $stderr.print stdout if $verbosity >= 2
119
+ else
120
+ out.error
121
+ $stderr.print stdout if $verbosity >= 1
122
+ exit_status = 1
123
+ break
135
124
  end
125
+ else
126
+ out.unknown
127
+ exit 1
136
128
  end
137
129
  end
130
+ end
138
131
 
139
- exit exit_status
140
- }
132
+ exit exit_status
133
+ end
data/paratele.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "paratele"
3
- s.version = "0.0.3"
3
+ s.version = "0.2"
4
4
  s.summary = "Provisioning at a distance"
5
5
  s.description = "Tele is a small provisioning framework that allows you to run bash scripts on remote servers over SSH."
6
- s.authors = ["Damian Janowski", "Michel Martens"]
7
- s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
8
- s.homepage = "http://github.com/djanowski/tele"
6
+ s.authors = ["Damian Janowski", "Michel Martens", "Harry Vangberg"]
7
+ s.email = ["djanowski@dimaion.com", "michel@soveran.com", "harry@vangberg.name"]
8
+ s.homepage = "http://github.com/vangberg/paratele"
9
9
 
10
10
  s.executables.push("paratele")
11
11
 
12
12
  s.add_dependency("clap")
13
13
 
14
- s.files = ["LICENSE", "README", "Rakefile", "bin/paratele", "bin/tele", "templates/.tele/layout.json", "templates/.tele/ssh_config", "paratele.gemspec", "tele.gemspec", "test/tele.rb"]
14
+ s.files = ["LICENSE", "README", "Rakefile", "bin/paratele", "paratele.gemspec", "test/tele.missing-recipes", "test/tele.rb", "test/tele.simple"]
15
15
  end
data/test/tele.rb CHANGED
@@ -7,28 +7,25 @@ def root(*args)
7
7
  File.join(ROOT, *args)
8
8
  end
9
9
 
10
- def tele(*args)
11
- sh("ruby #{root "bin/tele"} #{Shellwords.join args}")
10
+ def paratele(*args)
11
+ sh("ruby #{root "bin/paratele"} #{Shellwords.join args}")
12
12
  end
13
13
 
14
14
  def sh(cmd)
15
15
  Open3.capture3(cmd)
16
16
  end
17
17
 
18
- prepare do
19
- `rm -rf /tmp/tele`
20
- `mkdir /tmp/tele`
21
- end
22
-
23
- test "`tele run` without a config" do
24
- out, err, status = tele("run", "install")
18
+ test "`paratele run` without a config" do
19
+ Dir.chdir("test") {
20
+ out, err, status = paratele("run", "install", "production")
25
21
 
26
- assert err =~ /Couldn't find/
27
- assert_equal 1, status.exitstatus
22
+ assert err =~ /Couldn't find/
23
+ assert_equal 1, status.exitstatus
24
+ }
28
25
  end
29
26
 
30
- test "`tele run` with missing recipes" do
31
- out, err, status = tele("run", "deploy", "-d", "test/.tele.missing-recipes")
27
+ test "`paratele run` with missing recipes" do
28
+ out, err, status = paratele("run", "deploy", "production", "-d", "test/tele.missing-recipes")
32
29
 
33
30
  assert_equal 1, status.exitstatus
34
31
  assert out =~ /db-1/
@@ -36,8 +33,8 @@ test "`tele run` with missing recipes" do
36
33
  assert out !~ /cassandra: .*\?/
37
34
  end
38
35
 
39
- test "`tele run` successful" do
40
- out, err, status = tele("run", "install", "-d", "test/.tele.simple")
36
+ test "`paratele run` successful - production" do
37
+ out, err, status = paratele("run", "install", "production", "-d", "test/tele.simple")
41
38
 
42
39
  assert_equal 0, status.exitstatus
43
40
  assert out =~ /db-1/
@@ -45,10 +42,26 @@ test "`tele run` successful" do
45
42
  assert out =~ /redis: .*OK/
46
43
  assert out =~ /cdb: .*OK/
47
44
  assert out =~ /cassandra: .*OK/
45
+
46
+ assert out !~ /sta-1/
48
47
  end
49
48
 
50
- test "`tele run` with recipes missing a command" do
51
- out, err, status = tele("run", "status", "-d", "test/.tele.simple")
49
+ test "`paratele run` successful - staging" do
50
+ out, err, status = paratele("run", "install", "staging", "-d", "test/tele.simple")
51
+
52
+ assert_equal 0, status.exitstatus
53
+ assert out =~ /sta1/
54
+ assert out =~ /redis: .*OK/
55
+ assert out =~ /erb: .*OK/
56
+
57
+ assert out !~ /db-1/
58
+ assert out !~ /db-2/
59
+ assert out !~ /cdb:/
60
+ assert out !~ /cassandra:/
61
+ end
62
+
63
+ test "`paratele run` with recipes missing a command" do
64
+ out, err, status = paratele("run", "status", "production", "-d", "test/tele.simple")
52
65
 
53
66
  assert_equal 0, status.exitstatus
54
67
  assert out =~ /cassandra: .*\?/
@@ -56,8 +69,8 @@ test "`tele run` with recipes missing a command" do
56
69
  assert out =~ /redis: .*OK/
57
70
  end
58
71
 
59
- test "`tele run` with errors" do
60
- out, err, status = tele("run", "update", "-d", "test/.tele.simple")
72
+ test "`paratele run` with errors" do
73
+ out, err, status = paratele("run", "update", "production", "-d", "test/tele.simple")
61
74
 
62
75
  assert_equal 1, status.exitstatus
63
76
 
@@ -70,10 +83,11 @@ test "`tele run` with errors" do
70
83
  assert out =~ /redis: .*OK/
71
84
  end
72
85
 
73
- test "`tele run` with specific server" do
74
- out, err, status = tele("run", "install", "db-2", "-d", "test/.tele.simple")
86
+ test "`paratele run` with specific server" do
87
+ out, err, status = paratele("run", "install", "production:db-2", "-d", "test/tele.simple")
75
88
 
76
89
  assert_equal 0, status.exitstatus
90
+ assert out !~ /sta-1/
77
91
  assert out !~ /db-1/
78
92
  assert out !~ /cassandra/
79
93
  assert out !~ /cdb/
@@ -81,16 +95,17 @@ test "`tele run` with specific server" do
81
95
  assert out =~ /redis/
82
96
  end
83
97
 
84
- test "`tele run` with multiple server" do
85
- out, err, status = tele("run", "install", "db-2,db-1", "-d", "test/.tele.simple")
98
+ test "`paratele run` with multiple server" do
99
+ out, err, status = paratele("run", "install", "production:db-2,db-1", "-d", "test/tele.simple")
86
100
 
87
101
  assert_equal 0, status.exitstatus
102
+ assert out !~ /sta-1/
88
103
  assert out =~ /db-1/
89
104
  assert out =~ /db-2/
90
105
  end
91
106
 
92
- test "`tele run -v`" do
93
- out, err, status = tele("run", "update", "-v", "-d", "test/.tele.simple")
107
+ test "`paratele run -v`" do
108
+ out, err, status = paratele("run", "update", "production", "-v", "-d", "test/tele.simple")
94
109
 
95
110
  assert err =~ /Redis succesfully updated/
96
111
  assert err =~ /Updating Cassandra failed/
@@ -98,29 +113,11 @@ test "`tele run -v`" do
98
113
  assert out !~ /Updating Cassandra failed/
99
114
  end
100
115
 
101
- test "`tele run -q`" do
102
- out, err, status = tele("run", "update", "-q", "-d", "test/.tele.simple")
116
+ test "`paratele run -q`" do
117
+ out, err, status = paratele("run", "update", "production", "-q", "-d", "test/tele.simple")
103
118
 
104
119
  assert err !~ /Redis succesfully updated/
105
120
  assert err !~ /Updating Cassandra failed/
106
121
  assert out !~ /Redis succesfully updated/
107
122
  assert out !~ /Updating Cassandra failed/
108
123
  end
109
-
110
- __END__
111
-
112
- test "`tele init`" do
113
- `rm -rf test/tmp`
114
- `mkdir test/tmp`
115
-
116
- assert !File.exists?("test/tmp/.tele")
117
-
118
- Dir.chdir("test/tmp") do
119
- out, err = tele("init")
120
-
121
- assert File.exists?(".tele")
122
-
123
- out, err, status = tele("status")
124
- assert status.exitstatus == 0
125
- end
126
- end
metadata CHANGED
@@ -1,21 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paratele
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 3
9
- version: 0.0.3
4
+ prerelease:
5
+ version: "0.2"
10
6
  platform: ruby
11
7
  authors:
12
8
  - Damian Janowski
13
9
  - Michel Martens
10
+ - Harry Vangberg
14
11
  autorequire:
15
12
  bindir: bin
16
13
  cert_chain: []
17
14
 
18
- date: 2011-03-09 00:00:00 -03:00
15
+ date: 2011-04-07 00:00:00 +02:00
19
16
  default_executable:
20
17
  dependencies:
21
18
  - !ruby/object:Gem::Dependency
@@ -26,8 +23,6 @@ dependencies:
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- segments:
30
- - 0
31
26
  version: "0"
32
27
  type: :runtime
33
28
  version_requirements: *id001
@@ -35,6 +30,7 @@ description: Tele is a small provisioning framework that allows you to run bash
35
30
  email:
36
31
  - djanowski@dimaion.com
37
32
  - michel@soveran.com
33
+ - harry@vangberg.name
38
34
  executables:
39
35
  - paratele
40
36
  extensions: []
@@ -46,14 +42,10 @@ files:
46
42
  - README
47
43
  - Rakefile
48
44
  - bin/paratele
49
- - bin/tele
50
- - templates/.tele/layout.json
51
- - templates/.tele/ssh_config
52
45
  - paratele.gemspec
53
- - tele.gemspec
54
46
  - test/tele.rb
55
47
  has_rdoc: true
56
- homepage: http://github.com/djanowski/tele
48
+ homepage: http://github.com/vangberg/paratele
57
49
  licenses: []
58
50
 
59
51
  post_install_message:
@@ -66,21 +58,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
58
  requirements:
67
59
  - - ">="
68
60
  - !ruby/object:Gem::Version
69
- segments:
70
- - 0
71
61
  version: "0"
72
62
  required_rubygems_version: !ruby/object:Gem::Requirement
73
63
  none: false
74
64
  requirements:
75
65
  - - ">="
76
66
  - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
67
  version: "0"
80
68
  requirements: []
81
69
 
82
70
  rubyforge_project:
83
- rubygems_version: 1.3.7
71
+ rubygems_version: 1.6.2
84
72
  signing_key:
85
73
  specification_version: 3
86
74
  summary: Provisioning at a distance
data/bin/tele DELETED
@@ -1,140 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- help = File.expand_path(File.join("..", "README"), File.dirname(__FILE__))
4
-
5
- if ARGV.empty?
6
- exec "less #{help}"
7
- end
8
-
9
- require "clap"
10
- require "json"
11
- require "open3"
12
-
13
- def path(*parts)
14
- File.expand_path(File.join(*parts), ENV["TELE_HOME"])
15
- end
16
-
17
- def ssh(server, script)
18
- out, status = Open3.capture2e("ssh -T -F #{path("ssh_config")} #{server} < #{script}")
19
- [out, status.exitstatus]
20
- end
21
-
22
- def layout
23
- $layout ||= JSON.parse(File.read(path("layout.json")))
24
- end
25
-
26
- def servers
27
- layout["servers"]
28
- end
29
-
30
- def recipe_script(recipe, command)
31
- path("recipes", recipe, "#{command}.sh")
32
- end
33
-
34
- def run(server, recipe, command)
35
- script = recipe_script(recipe, command)
36
-
37
- if File.exist?(script)
38
- ssh(server, script)
39
- end
40
- end
41
-
42
- out = Module.new do
43
- def self.server(name)
44
- puts name
45
- end
46
-
47
- def self.error
48
- puts "\033[01;31mERROR\033[00m"
49
- end
50
-
51
- def self.ok
52
- puts "\033[01;32mOK\033[00m"
53
- end
54
-
55
- def self.missing
56
- puts "\033[01;33mMISSING\033[00m"
57
- end
58
-
59
- def self.done
60
- puts "\033[01;32mDONE\033[00m"
61
- end
62
-
63
- def self.unknown
64
- puts "?"
65
- end
66
- end
67
-
68
- ###
69
-
70
- ENV["TELE_HOME"] ||= File.join(Dir.pwd, ".tele")
71
-
72
- verbosity = 1
73
-
74
- commands = Clap.run ARGV,
75
- "-h" => lambda {
76
- exec "less #{help}"
77
- },
78
- "-q" => lambda {
79
- verbosity = 0
80
- },
81
- "-v" => lambda {
82
- verbosity = 2
83
- },
84
- "-d" => lambda {|path|
85
- ENV["TELE_HOME"] = File.join(Dir.pwd, path)
86
- }
87
-
88
- Clap.run commands,
89
- "init" => lambda {
90
- source = File.expand_path("../templates/.tele", File.dirname(__FILE__))
91
- target = File.expand_path(Dir.pwd)
92
-
93
- %x{cp -r #{source} #{target}}
94
- out.done
95
- }
96
-
97
- unless File.directory?(path)
98
- $stderr.puts "Couldn't find a .tele directory"
99
- exit 1
100
- end
101
-
102
- Clap.run commands,
103
- "run" => lambda {|command|
104
- if commands.size == 3
105
- selected = commands.last.split(",")
106
- servers.select! {|server| selected.include?(server)}
107
- end
108
-
109
- exit_status = 0
110
-
111
- servers.each do |server, recipes|
112
- out.server(server)
113
-
114
- recipes.each do |recipe|
115
- print " #{recipe}: "
116
-
117
- if File.exists?(path("recipes", recipe))
118
- stdout, status = run(server, recipe, command)
119
-
120
- case status
121
- when nil
122
- out.unknown
123
- when 0
124
- out.ok
125
- $stderr.print stdout if verbosity >= 2
126
- else
127
- out.error
128
- $stderr.print stdout if verbosity >= 1
129
- exit_status = 1
130
- break
131
- end
132
- else
133
- out.unknown
134
- exit 1
135
- end
136
- end
137
- end
138
-
139
- exit exit_status
140
- }
data/tele.gemspec DELETED
@@ -1,15 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "tele"
3
- s.version = "0.0.1"
4
- s.summary = "Provisioning at a distance"
5
- s.description = "Tele is a small provisioning framework that allows you to run bash scripts on remote servers over SSH."
6
- s.authors = ["Damian Janowski", "Michel Martens"]
7
- s.email = ["djanowski@dimaion.com", "michel@soveran.com"]
8
- s.homepage = "http://github.com/djanowski/tele"
9
-
10
- s.executables.push("tele")
11
-
12
- s.add_dependency("clap")
13
-
14
- s.files = ["LICENSE", "README", "Rakefile", "bin/tele", "templates/.tele/layout.json", "templates/.tele/ssh_config", "tele.gemspec", "test/tele.rb"]
15
- end
@@ -1,9 +0,0 @@
1
- {
2
- "roles": {
3
-
4
- },
5
-
6
- "servers": {
7
-
8
- }
9
- }
File without changes