supply_drop 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,7 +17,8 @@ then at the top of your deploy.rb
17
17
 
18
18
  ### Tasks
19
19
 
20
- cap puppet:bootstrap
20
+ cap puppet:bootstrap:ubuntu
21
+ cap puppet:bootstrap:osx
21
22
 
22
23
  This does a simple apt-get install of puppet on the target servers.
23
24
 
@@ -29,7 +30,7 @@ This will show you a list of the pending changes to be applied server-by-server.
29
30
 
30
31
  Applies the pending changes to all the servers.
31
32
 
32
- You can specify that one of your servers should be puppet by setting the :nopuppet flag to true, like so. It will then be skipped by all the above commands.
33
+ You can specify that one of your servers should not be puppeted by setting the :nopuppet flag to true, like so. It will then be skipped by all the above commands.
33
34
 
34
35
  role :weird_thing, '33.33.33.33', :nopuppet => true
35
36
 
@@ -51,12 +52,16 @@ allows you to override the puppet command that is run if puppet is not on the pa
51
52
 
52
53
  set :puppet_lib, "#{puppet_destination}/modules"
53
54
 
54
- the value of the PUPPETLIB environment variable, the location of your puppet modules
55
+ the value of the PUPPETLIB environment variable, the location of your puppet modules.
55
56
 
56
57
  set :puppet_parameters, 'puppet.pp'
57
58
 
58
59
  the parameters that are passed to the puppet call.
59
60
 
61
+ set :puppet_excludes, %w(.git .svn)
62
+
63
+ these are patterns that are passed as rsync --exclude flags when pushing your puppet configs to the box.
64
+
60
65
  ### How to contribute
61
66
 
62
67
  If you write anything complicated, write a test for it. Test that your changes work using vagrant. Send a pull request. Easy peezy.
data/lib/supply_drop.rb CHANGED
@@ -6,13 +6,27 @@ Capistrano::Configuration.instance.load do
6
6
  set :puppet_destination, '/tmp/supply_drop'
7
7
  set :puppet_command, 'puppet'
8
8
  set :puppet_lib, "#{puppet_destination}/modules"
9
- set :puppet_parameters, 'puppet.pp'
9
+ set :puppet_parameters, lambda { puppet_verbose ? '--debug --trace puppet.pp' : 'puppet.pp' }
10
+ set :puppet_verbose, false
11
+ set :puppet_excludes, %w(.git .svn)
12
+ set :puppet_stream_output, false
10
13
 
11
- desc "installs puppet"
12
- task :bootstrap, :except => { :nopuppet => true } do
13
- run "mkdir -p #{puppet_destination}"
14
- run "#{sudo} apt-get update"
15
- run "#{sudo} apt-get install -y puppet rsync"
14
+ namespace :bootstrap do
15
+ desc "installs puppet via rubygems on an osx host"
16
+ task :osx do
17
+ if fetch(:use_sudo, true)
18
+ run "#{sudo} gem install puppet --no-ri --no-rdoc"
19
+ else
20
+ run "gem install puppet --no-ri --no-rdoc"
21
+ end
22
+ end
23
+
24
+ desc "installs puppet via apt on an ubuntu host"
25
+ task :ubuntu do
26
+ run "mkdir -p #{puppet_destination}"
27
+ run "#{sudo} apt-get update"
28
+ run "#{sudo} apt-get install -y puppet rsync"
29
+ end
16
30
  end
17
31
 
18
32
  desc "pushes the current puppet configuration to the server"
@@ -20,10 +34,10 @@ Capistrano::Configuration.instance.load do
20
34
  find_servers_for_task(current_task).each do |server|
21
35
  rsync_cmd = Rsync.command(
22
36
  puppet_source,
23
- "#{server.user || user}@#{server.host}:#{puppet_destination}/",
37
+ Rsync.remote_address(server.user || fetch(:user, ENV['USER']), server.host, puppet_destination),
24
38
  :delete => true,
25
- :excludes => ['.git'],
26
- :ssh => { :keys => ssh_options[:keys] }
39
+ :excludes => puppet_excludes,
40
+ :ssh => { :keys => ssh_options[:keys], :config => ssh_options[:config] }
27
41
  )
28
42
  logger.debug rsync_cmd
29
43
  system rsync_cmd
@@ -44,20 +58,28 @@ Capistrano::Configuration.instance.load do
44
58
  end
45
59
 
46
60
  def puppet(command = :noop)
47
- puppet_cmd = "cd #{puppet_destination} && #{sudo} PUPPETLIB=#{puppet_lib} #{puppet_command} #{puppet_parameters}"
61
+ sudo_cmd = fetch(:use_sudo, true) ? sudo : ''
62
+ puppet_cmd = "cd #{puppet_destination} && #{sudo_cmd} #{puppet_command} --modulepath=#{puppet_lib} #{puppet_parameters}"
48
63
  flag = command == :noop ? '--noop' : ''
49
64
 
50
65
  outputs = {}
51
66
  begin
52
67
  run "#{puppet_cmd} #{flag}" do |channel, stream, data|
53
- outputs[channel[:host]] ||= ""
54
- outputs[channel[:host]] << data
68
+ if puppet_stream_output
69
+ print data
70
+ $stdout.flush
71
+ else
72
+ outputs[channel[:host]] ||= ""
73
+ outputs[channel[:host]] << data
74
+ end
55
75
  end
56
76
  logger.debug "Puppet #{command} complete."
57
77
  ensure
58
- outputs.each_pair do |host, output|
59
- logger.info "Puppet output for #{host}"
60
- logger.debug output, "#{host}"
78
+ unless puppet_stream_output
79
+ outputs.each_pair do |host, output|
80
+ logger.info "Puppet output for #{host}"
81
+ logger.debug output, "#{host}"
82
+ end
61
83
  end
62
84
  end
63
85
  end
@@ -9,18 +9,26 @@ class Rsync
9
9
  "rsync #{flags.compact.join(' ')} #{from} #{to}"
10
10
  end
11
11
 
12
+ def remote_address(user, host, path)
13
+ user_with_host = [user, host].compact.join('@')
14
+ [user_with_host, path].join(':')
15
+ end
16
+
12
17
  def excludes(patterns)
13
18
  [patterns].flatten.map { |p| "--exclude=#{p}" }
14
19
  end
15
20
 
16
21
  def ssh_options(options)
17
22
  mapped_options = options.map do |key, value|
18
- if key == :keys && value != nil
19
- [value].flatten.select { |k| File.exist?(k) }.map { |k| "-i #{k}" }
23
+ next unless value
24
+
25
+ case key
26
+ when :keys then [value].flatten.select { |k| File.exist?(k) }.map { |k| "-i #{k}" }
27
+ when :config then "-F #{value}"
20
28
  end
21
- end
29
+ end.compact
22
30
 
23
- %[-e "ssh #{mapped_options.join(' ')}"]
31
+ %[-e "ssh #{mapped_options.join(' ')}"] unless mapped_options.empty?
24
32
  end
25
33
  end
26
34
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: supply_drop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
4
+ hash: 15
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Pitluga
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-03 00:00:00 -05:00
18
+ date: 2011-07-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements: []
68
68
 
69
69
  rubyforge_project:
70
- rubygems_version: 1.4.1
70
+ rubygems_version: 1.3.7
71
71
  signing_key:
72
72
  specification_version: 3
73
73
  summary: Serverless puppet with capistrano