marionetta 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -36,7 +36,7 @@ above, we will now iterate over the servers:
36
36
  ``` ruby
37
37
  servers.each_server do |s|
38
38
  # Run command on each server in parallel
39
- Marionetta::SSH.new(s).run('whoami')
39
+ Marionetta::SSH.new(s).ssh('whoami')
40
40
  end
41
41
  ```
42
42
 
data/Rakefile CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
4
2
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
6
-
7
3
  require 'marionetta'
8
4
 
5
+ Bundler::GemHelper.install_tasks
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
9
8
  task(:default => :spec)
10
9
 
11
10
  task(:gem => :spec) do
data/lib/marionetta.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  module Marionetta
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  DESCRIPTION = 'For lightweight puppet mastery. Organise
4
4
  multiple machines via rsync and SSH rather
5
5
  than using puppet master'
6
6
 
7
- require_relative 'marionetta/ssh'
8
- require_relative 'marionetta/manipulators'
9
- require_relative 'marionetta/group'
10
-
11
7
  def self.default_server()
12
8
  {
13
9
  :ssh => {
@@ -18,6 +14,7 @@ module Marionetta
18
14
  :command => 'rsync',
19
15
  :flags => ["-azP", "--delete"],
20
16
  },
17
+ :logger => Logger.new($stdout),
21
18
  }
22
19
  end
23
20
  end
@@ -1,10 +1,22 @@
1
+ require 'open4'
2
+
1
3
  module Marionetta
2
- class SSH
4
+ class CommandRunner
3
5
  attr_reader :server
4
6
 
5
7
  def initialize(server)
6
8
  @server = server
7
9
  end
10
+
11
+ def system(*args)
12
+ status = Open4::popen4(*args) do |pid, stdin, stdout, stderr|
13
+ server[:logger].info(args.join(' '))
14
+ server[:logger].debug(stdout.read)
15
+ server[:logger].debug(stderr.read)
16
+ end
17
+
18
+ return status.exitstatus
19
+ end
8
20
 
9
21
  def get(local_dir, file)
10
22
  rsync("#{server[:hostname]}", local_dir)
@@ -32,7 +44,7 @@ module Marionetta
32
44
  system(*rsync_cmd.flatten)
33
45
  end
34
46
 
35
- def run(command)
47
+ def ssh(command)
36
48
  ssh_cmd = [server[:ssh][:command]]
37
49
 
38
50
  if server[:ssh].has_key?(:flags)
@@ -1,3 +1,5 @@
1
+ require 'marionetta'
2
+ require 'marionetta/manipulators'
1
3
  require 'celluloid'
2
4
 
3
5
  module Marionetta
@@ -1,18 +1,41 @@
1
+ require 'marionetta'
2
+ require 'marionetta/command_runner'
3
+
1
4
  module Marionetta
2
5
  module Manipulators
3
6
  class PuppetManipulator
7
+ attr_writer :cmd
8
+
4
9
  def self.tasks()
5
10
  [:install, :update]
6
11
  end
7
12
 
8
- attr_reader :server
9
-
10
13
  def initialize(server)
11
14
  @server = server
12
15
  end
13
16
 
14
- def ssh()
15
- @ssh ||= SSH.new(server)
17
+ def install()
18
+ install_deb_repo
19
+ install_deb
20
+ end
21
+
22
+ def installed?()
23
+ cmd.ssh('which puppet')
24
+ end
25
+
26
+ def update()
27
+ install unless installed?
28
+ archive_files
29
+ send_archive
30
+ apply_archive
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :server
36
+
37
+ def cmd()
38
+ @cmd ||= CommandRunner.new(server)
16
39
  end
17
40
 
18
41
  def install_deb_repo()
@@ -26,7 +49,7 @@ module Marionetta
26
49
 
27
50
  repo_check_cmd = "test -f /etc/apt/sources.list.d/puppetlabs.list"
28
51
 
29
- ssh.run("#{repo_check_cmd} || { #{repo_install_cmd}; }")
52
+ cmd.ssh("#{repo_check_cmd} || { #{repo_install_cmd}; }")
30
53
  end
31
54
 
32
55
  def install_deb()
@@ -35,16 +58,7 @@ module Marionetta
35
58
  'sudo aptitude install -y puppet'
36
59
  ].join(' && ')
37
60
 
38
- ssh.run("which puppet || { #{install_cmd}; }")
39
- end
40
-
41
- def install()
42
- install_deb_repo
43
- install_deb
44
- end
45
-
46
- def installed?()
47
- ssh.run('which puppet')
61
+ cmd.ssh("which puppet || { #{install_cmd}; }")
48
62
  end
49
63
 
50
64
  def archive_files()
@@ -61,11 +75,11 @@ module Marionetta
61
75
  cmds << 'cd /tmp'
62
76
  cmds << 'tar cvfz puppet.tar.gz puppet'
63
77
 
64
- system(cmds.join(' && '))
78
+ cmd.system(cmds.join(' && '))
65
79
  end
66
80
 
67
81
  def send_archive()
68
- ssh.rsync('/tmp/puppet.tar.gz', "#{server[:hostname]}:/tmp")
82
+ cmd.rsync('/tmp/puppet.tar.gz', "#{server[:hostname]}:/tmp")
69
83
  end
70
84
 
71
85
  def apply_archive()
@@ -89,14 +103,7 @@ module Marionetta
89
103
 
90
104
  cmds << puppet_cmd
91
105
 
92
- ssh.run(cmds.join(' && '))
93
- end
94
-
95
- def update()
96
- install unless installed?
97
- archive_files
98
- send_archive
99
- apply_archive
106
+ cmd.ssh(cmds.join(' && '))
100
107
  end
101
108
  end
102
109
  end
@@ -1,4 +1,5 @@
1
1
  require 'marionetta'
2
+ require 'marionetta/manipulators'
2
3
  require 'rake'
3
4
 
4
5
  module Marionetta
@@ -24,7 +25,7 @@ module Marionetta
24
25
  def install_group_tasks_for(group)
25
26
  Manipulators.all.each do |manipulator_name, manipulator_class|
26
27
  manipulator_class.tasks.each do |method_name|
27
- desc("#{manipulator_name} #{method_name} (marionetta)")
28
+ desc("#{method_name} #{manipulator_name} on #{group.name} (marionetta)")
28
29
  task(task_name(group, manipulator_name, method_name)) do
29
30
  group.manipulate_each_server(manipulator_name, method_name)
30
31
  end
data/marionetta.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.require_paths = ["lib"]
17
17
 
18
+ s.add_dependency('open4')
18
19
  s.add_dependency('celluloid')
19
20
 
20
21
  s.add_development_dependency('rake')
@@ -1,4 +1,4 @@
1
- require 'marionetta'
1
+ require 'spec_helper'
2
2
  require 'marionetta/group'
3
3
 
4
4
  describe Marionetta::Group do
@@ -1,3 +1,4 @@
1
+ require 'spec_helper'
1
2
  require 'marionetta/manipulators'
2
3
 
3
4
  describe Marionetta::Manipulators do
@@ -1,4 +1,5 @@
1
- require 'marionetta/manipulators'
1
+ require 'spec_helper'
2
+ require 'marionetta/manipulators/puppet_manipulator'
2
3
 
3
4
  describe Marionetta::Manipulators::PuppetManipulator do
4
5
  it 'should manipulate one server map' do
@@ -1,10 +1,21 @@
1
- require 'marionetta'
1
+ require 'spec_helper'
2
2
  require 'marionetta/rake_helper'
3
3
 
4
4
  describe Marionetta::RakeHelper do
5
5
  it 'should install rake tasks' do
6
- group = Marionetta::Group.new(:staging)
7
- Marionetta::RakeHelper.new(group).install_group_tasks
6
+ vagrant = Marionetta::Group.new(:vagrant)
7
+
8
+ vagrant.add_server do |s|
9
+ s[:hostname] = 'vagrant@192.168.33.11'
10
+ ssh_key_path = File.dirname(__FILE__)+'/vagrant/key'
11
+ s[:ssh][:flags] = ['-i', ssh_key_path]
12
+ s[:rsync][:flags] = ['-azP', '-e', "ssh -i #{ssh_key_path}", '--delete']
13
+ s[:puppet] = {:manifest => File.dirname(__FILE__)+'/puppet/manifest.pp'}
14
+ end
15
+
16
+ Marionetta::RakeHelper.new(vagrant).install_group_tasks
8
17
  Rake::Task.tasks.count.should > 0
18
+
19
+ Rake::Task['vagrant:puppet:update'].invoke
9
20
  end
10
21
  end
@@ -1,8 +1,5 @@
1
+ require 'spec_helper'
1
2
  require 'marionetta'
2
- require 'vagrant'
3
-
4
- env = Vagrant::Environment.new(:cwd => File.dirname(__FILE__)+'/vagrant')
5
- env.cli('up')
6
3
 
7
4
  describe Marionetta do
8
5
  it 'should provide a default SSH map' do
@@ -0,0 +1,7 @@
1
+ require 'vagrant'
2
+ require 'celluloid'
3
+
4
+ env = Vagrant::Environment.new(:cwd => File.dirname(__FILE__)+'/vagrant')
5
+ env.cli('up')
6
+
7
+ Celluloid.logger.level = Logger::WARN
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marionetta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-17 00:00:00.000000000 Z
12
+ date: 2012-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: open4
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: celluloid
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -88,11 +104,11 @@ files:
88
104
  - README.md
89
105
  - Rakefile
90
106
  - lib/marionetta.rb
107
+ - lib/marionetta/command_runner.rb
91
108
  - lib/marionetta/group.rb
92
109
  - lib/marionetta/manipulators.rb
93
110
  - lib/marionetta/manipulators/puppet_manipulator.rb
94
111
  - lib/marionetta/rake_helper.rb
95
- - lib/marionetta/ssh.rb
96
112
  - marionetta.gemspec
97
113
  - spec/marionetta_group_spec.rb
98
114
  - spec/marionetta_manipulators_spec.rb
@@ -100,6 +116,7 @@ files:
100
116
  - spec/marionetta_rake_helper_spec.rb
101
117
  - spec/marionetta_spec.rb
102
118
  - spec/puppet/manifest.pp
119
+ - spec/spec_helper.rb
103
120
  - spec/vagrant/Vagrantfile
104
121
  - spec/vagrant/key
105
122
  homepage: https://github.com/DrPheltRight/marionetta
@@ -134,5 +151,6 @@ test_files:
134
151
  - spec/marionetta_rake_helper_spec.rb
135
152
  - spec/marionetta_spec.rb
136
153
  - spec/puppet/manifest.pp
154
+ - spec/spec_helper.rb
137
155
  - spec/vagrant/Vagrantfile
138
156
  - spec/vagrant/key