capchef 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/capchef.rb +2 -1
  2. data/lib/capchef/chef_recipes.rb +53 -44
  3. metadata +18 -9
data/lib/capchef.rb CHANGED
@@ -120,6 +120,7 @@ module Capchef
120
120
  cmd = remote_script
121
121
  cmd += ' ' + args if args
122
122
  surun cap, cmd, options, &block
123
- cap.run "rm -rf #{script_dir}", options
123
+ ensure
124
+ cap.run "rm -rf #{script_dir}", options unless ENV['CAPCHEF_KEEP_TEMP']
124
125
  end
125
126
  end
@@ -19,6 +19,8 @@ Capistrano::Configuration.instance.load do
19
19
  namespace :chef do
20
20
  desc 'Install chef recipes on remote machines.'
21
21
  task :default do
22
+ # If the user specifies the HOSTS environment variable, we need to temporarily clear it or it will override the :hosts option
23
+ save_hosts_env = ENV['HOSTS']
22
24
  Capchef.prepend_path(chef_solo_path) if exists?(:chef_solo_path)
23
25
 
24
26
  config = Capchef.nodes_config
@@ -30,58 +32,65 @@ Capistrano::Configuration.instance.load do
30
32
  remote_roles_tgz = "#{remote_tmpdir}/roles.tgz"
31
33
 
32
34
  valid_hosts = []
33
- find_servers_for_task(current_task).each do |s|
34
- host_config = config[s.host]
35
- if host_config
36
- valid_hosts << s.host
37
- put host_config.to_json, remote_node_file, :hosts => s.host
38
- else
39
- $stderr.puts "WARNING: #{s.host} not configured in nodes.yml, skipping"
35
+ all_hosts = find_servers_for_task(current_task).map {|s| s.host}
36
+ # From here down, all cap methods must specify the :hosts option
37
+ begin
38
+ ENV['HOSTS'] = nil
39
+ all_hosts.each do |host|
40
+ host_config = config[host]
41
+ if host_config
42
+ valid_hosts << host
43
+ put host_config.to_json, remote_node_file, :hosts => host
44
+ else
45
+ $stderr.puts "WARNING: #{host} not configured in nodes.yml, skipping"
46
+ end
47
+ end
48
+ if valid_hosts.empty?
49
+ $stderr.puts 'No configured hosts'
50
+ exit 1
40
51
  end
41
- end
42
- if valid_hosts.empty?
43
- $stderr.puts 'No configured hosts'
44
- exit 1
45
- end
46
52
 
47
- solo_rb = "file_cache_path '/etc/chef'\ncookbook_path '/etc/chef/cookbooks'\nrole_path '/etc/chef/roles'\n"
48
- put solo_rb, remote_solo_file, :hosts => valid_hosts
49
- begin
50
- tmp_cookbooks_tgz = Tempfile.new('cookbooks')
51
- Dir.chdir('chef-repo') do
52
- Minitar.pack('cookbooks', Zlib::GzipWriter.new(tmp_cookbooks_tgz))
53
- tmp_cookbooks_tgz.close
54
- upload tmp_cookbooks_tgz.path, remote_cookbooks_tgz, :hosts => valid_hosts
53
+ solo_rb = "file_cache_path '/etc/chef'\ncookbook_path '/etc/chef/cookbooks'\nrole_path '/etc/chef/roles'\nhttp_proxy ENV['http_proxy'] if ENV['http_proxy']\n"
54
+ put solo_rb, remote_solo_file, :hosts => valid_hosts
55
+ begin
56
+ tmp_cookbooks_tgz = Tempfile.new('cookbooks')
57
+ Dir.chdir('chef-repo') do
58
+ Minitar.pack('cookbooks', Zlib::GzipWriter.new(tmp_cookbooks_tgz))
59
+ tmp_cookbooks_tgz.close
60
+ upload tmp_cookbooks_tgz.path, remote_cookbooks_tgz, :hosts => valid_hosts
55
61
 
56
- sio_roles_tgz = StringIO.new
57
- gzip = Zlib::GzipWriter.new(sio_roles_tgz)
58
- Minitar::Writer.open(gzip) do |tar|
59
- #Minitar::Writer.open(sio_roles_tgz) do |tar|
60
- Find.find('roles') do |role_file|
61
- # TODO: This does not work (how do I specify a role in JSON?
62
- if role_file.match(/\.yml$/)
63
- data = YAML.load(ERB.new(File.read(role_file), nil, '-').result(binding)).to_json
64
- new_role_file = role_file.sub(/\.yml$/, '.json')
65
- tar.add_file_simple(new_role_file, :size=>data.size, :mode=>0644, :mtime=>File.mtime(role_file)) { |f| f.write(data) }
66
- else
67
- Minitar.pack_file(role_file, tar)
62
+ sio_roles_tgz = StringIO.new
63
+ gzip = Zlib::GzipWriter.new(sio_roles_tgz)
64
+ Minitar::Writer.open(gzip) do |tar|
65
+ #Minitar::Writer.open(sio_roles_tgz) do |tar|
66
+ Find.find('roles') do |role_file|
67
+ # TODO: This does not work (how do I specify a role in JSON?
68
+ if role_file.match(/\.yml$/)
69
+ data = YAML.load(ERB.new(File.read(role_file), nil, '-').result(binding)).to_json
70
+ new_role_file = role_file.sub(/\.yml$/, '.json')
71
+ tar.add_file_simple(new_role_file, :size=>data.size, :mode=>0644, :mtime=>File.mtime(role_file)) { |f| f.write(data) }
72
+ else
73
+ Minitar.pack_file(role_file, tar)
74
+ end
68
75
  end
69
76
  end
77
+ gzip.close
78
+ put sio_roles_tgz.string, remote_roles_tgz, :hosts => valid_hosts
70
79
  end
71
- gzip.close
72
- put sio_roles_tgz.string, remote_roles_tgz, :hosts => valid_hosts
80
+ Capchef.surun(self, [
81
+ 'mkdir -p /etc/chef',
82
+ 'cd /etc/chef',
83
+ 'rm -rf cookbooks roles',
84
+ "tar zxf #{remote_cookbooks_tgz}",
85
+ "tar zxf #{remote_roles_tgz}",
86
+ "chef-solo -c #{remote_solo_file} -j #{remote_node_file}"
87
+ ], :hosts => valid_hosts)
88
+ ensure
89
+ tmp_cookbooks_tgz.unlink
73
90
  end
74
- Capchef.surun(self, [
75
- 'mkdir -p /etc/chef',
76
- 'cd /etc/chef',
77
- 'rm -rf cookbooks roles',
78
- "tar zxf #{remote_cookbooks_tgz}",
79
- "tar zxf #{remote_roles_tgz}",
80
- "chef-solo -c #{remote_solo_file} -j #{remote_node_file}"
81
- ], :hosts => valid_hosts)
82
91
  ensure
83
- tmp_cookbooks_tgz.unlink
84
- run "rm -rf #{remote_tmpdir}"
92
+ ENV['HOSTS'] = save_hosts_env
93
+ run "rm -rf #{remote_tmpdir}" unless ENV['CAPCHEF_KEEP_TEMP']
85
94
  end
86
95
  end
87
96
  end
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capchef
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.5
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 6
9
+ version: 0.0.6
6
10
  platform: ruby
7
11
  authors:
8
12
  - Brad Pardee
@@ -10,17 +14,18 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-09-20 00:00:00 -04:00
17
+ date: 2011-09-21 00:00:00 -04:00
14
18
  default_executable:
15
19
  dependencies:
16
20
  - !ruby/object:Gem::Dependency
17
21
  name: capistrano
18
22
  prerelease: false
19
23
  requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
24
  requirements:
22
25
  - - ">="
23
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
24
29
  version: "0"
25
30
  type: :runtime
26
31
  version_requirements: *id001
@@ -28,10 +33,11 @@ dependencies:
28
33
  name: json
29
34
  prerelease: false
30
35
  requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
36
  requirements:
33
37
  - - ">="
34
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
35
41
  version: "0"
36
42
  type: :runtime
37
43
  version_requirements: *id002
@@ -39,10 +45,11 @@ dependencies:
39
45
  name: minitar
40
46
  prerelease: false
41
47
  requirement: &id003 !ruby/object:Gem::Requirement
42
- none: false
43
48
  requirements:
44
49
  - - ">="
45
50
  - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
46
53
  version: "0"
47
54
  type: :runtime
48
55
  version_requirements: *id003
@@ -72,21 +79,23 @@ rdoc_options: []
72
79
  require_paths:
73
80
  - lib
74
81
  required_ruby_version: !ruby/object:Gem::Requirement
75
- none: false
76
82
  requirements:
77
83
  - - ">="
78
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
79
87
  version: "0"
80
88
  required_rubygems_version: !ruby/object:Gem::Requirement
81
- none: false
82
89
  requirements:
83
90
  - - ">="
84
91
  - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
85
94
  version: "0"
86
95
  requirements: []
87
96
 
88
97
  rubyforge_project:
89
- rubygems_version: 1.5.1
98
+ rubygems_version: 1.3.6
90
99
  signing_key:
91
100
  specification_version: 3
92
101
  summary: Chef capistrano recipes