chef 0.10.10.beta.1 → 0.10.10.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/README.rdoc +1 -1
  2. data/distro/common/html/chef-client.8.html +3 -3
  3. data/distro/common/html/chef-expander.8.html +3 -3
  4. data/distro/common/html/chef-expanderctl.8.html +3 -3
  5. data/distro/common/html/chef-server-webui.8.html +3 -3
  6. data/distro/common/html/chef-server.8.html +3 -3
  7. data/distro/common/html/chef-solo.8.html +3 -3
  8. data/distro/common/html/chef-solr.8.html +3 -3
  9. data/distro/common/html/knife-bootstrap.1.html +3 -3
  10. data/distro/common/html/knife-client.1.html +3 -3
  11. data/distro/common/html/knife-configure.1.html +3 -3
  12. data/distro/common/html/knife-cookbook-site.1.html +3 -3
  13. data/distro/common/html/knife-cookbook.1.html +3 -3
  14. data/distro/common/html/knife-data-bag.1.html +7 -3
  15. data/distro/common/html/knife-environment.1.html +3 -3
  16. data/distro/common/html/knife-exec.1.html +3 -3
  17. data/distro/common/html/knife-index.1.html +3 -3
  18. data/distro/common/html/knife-node.1.html +3 -3
  19. data/distro/common/html/knife-role.1.html +3 -3
  20. data/distro/common/html/knife-search.1.html +3 -3
  21. data/distro/common/html/knife-ssh.1.html +3 -3
  22. data/distro/common/html/knife-status.1.html +3 -3
  23. data/distro/common/html/knife-tag.1.html +3 -3
  24. data/distro/common/html/knife.1.html +3 -3
  25. data/distro/common/html/shef.1.html +3 -3
  26. data/distro/common/man/man1/knife-bootstrap.1 +1 -1
  27. data/distro/common/man/man1/knife-client.1 +1 -1
  28. data/distro/common/man/man1/knife-configure.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook-site.1 +1 -1
  30. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  31. data/distro/common/man/man1/knife-data-bag.1 +7 -1
  32. data/distro/common/man/man1/knife-environment.1 +1 -1
  33. data/distro/common/man/man1/knife-exec.1 +1 -1
  34. data/distro/common/man/man1/knife-index.1 +1 -1
  35. data/distro/common/man/man1/knife-node.1 +1 -1
  36. data/distro/common/man/man1/knife-role.1 +1 -1
  37. data/distro/common/man/man1/knife-search.1 +1 -1
  38. data/distro/common/man/man1/knife-ssh.1 +1 -1
  39. data/distro/common/man/man1/knife-status.1 +1 -1
  40. data/distro/common/man/man1/knife-tag.1 +1 -1
  41. data/distro/common/man/man1/knife.1 +1 -1
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/distro/common/markdown/man1/knife-data-bag.mkd +4 -0
  51. data/lib/chef/application/client.rb +15 -1
  52. data/lib/chef/application/solo.rb +15 -1
  53. data/lib/chef/application/windows_service.rb +15 -1
  54. data/lib/chef/certificate.rb +18 -51
  55. data/lib/chef/client.rb +31 -1
  56. data/lib/chef/json_compat.rb +1 -1
  57. data/lib/chef/knife.rb +23 -6
  58. data/lib/chef/knife/bootstrap.rb +7 -0
  59. data/lib/chef/knife/bootstrap/archlinux-gems.erb +1 -1
  60. data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
  61. data/lib/chef/knife/bootstrap/chef-full.erb +1 -1
  62. data/lib/chef/knife/bootstrap/fedora13-gems.erb +1 -1
  63. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -1
  64. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +1 -1
  65. data/lib/chef/knife/core/bootstrap_context.rb +4 -0
  66. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  67. data/lib/chef/knife/core/object_loader.rb +39 -2
  68. data/lib/chef/knife/data_bag_from_file.rb +68 -19
  69. data/lib/chef/knife/ssh.rb +2 -1
  70. data/lib/chef/platform.rb +8 -0
  71. data/lib/chef/provider/cron.rb +70 -56
  72. data/lib/chef/provider/cron/solaris.rb +16 -143
  73. data/lib/chef/provider/deploy.rb +1 -1
  74. data/lib/chef/provider/group/groupadd.rb +1 -4
  75. data/lib/chef/provider/mdadm.rb +1 -1
  76. data/lib/chef/provider/mount/mount.rb +14 -2
  77. data/lib/chef/provider/package.rb +7 -1
  78. data/lib/chef/provider/package/freebsd.rb +30 -6
  79. data/lib/chef/provider/package/pacman.rb +1 -0
  80. data/lib/chef/provider/package/rubygems.rb +2 -4
  81. data/lib/chef/provider/remote_directory.rb +1 -1
  82. data/lib/chef/provider/service/freebsd.rb +32 -46
  83. data/lib/chef/provider/service/init.rb +8 -5
  84. data/lib/chef/provider/service/simple.rb +57 -48
  85. data/lib/chef/provider/service/upstart.rb +13 -5
  86. data/lib/chef/provider/user/useradd.rb +6 -1
  87. data/lib/chef/resource/mdadm.rb +9 -0
  88. data/lib/chef/resource/service.rb +9 -1
  89. data/lib/chef/rest.rb +9 -9
  90. data/lib/chef/version.rb +1 -1
  91. metadata +177 -28
@@ -326,7 +326,8 @@ class Chef
326
326
 
327
327
  def configure_attribute
328
328
  config[:attribute] = (Chef::Config[:knife][:ssh_attribute] ||
329
- config[:attribute]).strip
329
+ config[:attribute] ||
330
+ "fqdn").strip
330
331
  end
331
332
 
332
333
  def csshx
@@ -73,6 +73,14 @@ class Chef
73
73
  :mdadm => Chef::Provider::Mdadm
74
74
  }
75
75
  },
76
+ :linaro => {
77
+ :default => {
78
+ :package => Chef::Provider::Package::Apt,
79
+ :service => Chef::Provider::Service::Debian,
80
+ :cron => Chef::Provider::Cron,
81
+ :mdadm => Chef::Provider::Mdadm
82
+ }
83
+ },
76
84
  :linuxmint => {
77
85
  :default => {
78
86
  :package => Chef::Provider::Package::Apt,
@@ -25,7 +25,9 @@ class Chef
25
25
  class Cron < Chef::Provider
26
26
  include Chef::Mixin::Command
27
27
 
28
- CRON_PATTERN = /([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s(.*)/
28
+ CRON_PATTERN = /\A([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s(.*)/
29
+ ENV_PATTERN = /\A(\S+)=(\S*)/
30
+
29
31
  CRON_ATTRIBUTES = [:minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home, :environment]
30
32
 
31
33
  def initialize(new_resource, run_context)
@@ -39,21 +41,16 @@ class Chef
39
41
  crontab_lines = []
40
42
  @current_resource = Chef::Resource::Cron.new(@new_resource.name)
41
43
  @current_resource.user(@new_resource.user)
42
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
43
- stdout.each_line { |line| crontab_lines << line }
44
- end
45
- if status.exitstatus > 1
46
- raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
47
- elsif status.exitstatus == 0
44
+ if crontab = read_crontab
48
45
  cron_found = false
49
- crontab_lines.each do |line|
46
+ crontab.each_line do |line|
50
47
  case line.chomp
51
48
  when "# Chef Name: #{@new_resource.name}"
52
49
  Chef::Log.debug("Found cron '#{@new_resource.name}'")
53
50
  cron_found = true
54
51
  @cron_exists = true
55
52
  next
56
- when /^(\S*)=(\S*)/
53
+ when ENV_PATTERN
57
54
  set_environment_var($1, $2) if cron_found
58
55
  next
59
56
  when CRON_PATTERN
@@ -68,11 +65,12 @@ class Chef
68
65
  end
69
66
  next
70
67
  else
68
+ cron_found=false # We've got a Chef comment with no following crontab line
71
69
  next
72
70
  end
73
71
  end
74
72
  Chef::Log.debug("Cron '#{@new_resource.name}' not found") unless @cron_exists
75
- elsif status.exitstatus == 1
73
+ else
76
74
  Chef::Log.debug("Cron empty for '#{@new_resource.user}'")
77
75
  @cron_empty = true
78
76
  end
@@ -80,7 +78,7 @@ class Chef
80
78
  @current_resource
81
79
  end
82
80
 
83
- def compare_cron
81
+ def cron_different?
84
82
  CRON_ATTRIBUTES.any? do |cron_var|
85
83
  !@new_resource.send(cron_var).nil? && @new_resource.send(cron_var) != @current_resource.send(cron_var)
86
84
  end
@@ -101,46 +99,44 @@ class Chef
101
99
  newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
102
100
 
103
101
  if @cron_exists
104
- unless compare_cron
102
+ unless cron_different?
105
103
  Chef::Log.debug("Skipping existing cron entry '#{@new_resource.name}'")
106
104
  return
107
105
  end
108
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
109
- stdout.each_line do |line|
110
- case line.chomp
111
- when "# Chef Name: #{@new_resource.name}"
112
- cron_found = true
106
+ read_crontab.each_line do |line|
107
+ case line.chomp
108
+ when "# Chef Name: #{@new_resource.name}"
109
+ cron_found = true
110
+ next
111
+ when ENV_PATTERN
112
+ crontab << line unless cron_found
113
+ next
114
+ when CRON_PATTERN
115
+ if cron_found
116
+ cron_found = false
117
+ crontab << newcron
113
118
  next
114
- when CRON_PATTERN
115
- if cron_found
116
- cron_found = false
117
- crontab << newcron
118
- next
119
- end
120
- else
121
- next if cron_found
122
119
  end
123
- crontab << line
120
+ else
121
+ if cron_found # We've got a Chef comment with no following crontab line
122
+ crontab << newcron
123
+ cron_found = false
124
+ end
124
125
  end
126
+ crontab << line
125
127
  end
128
+ # Handle edge case where the Chef comment is the last line in the current crontab
129
+ crontab << newcron if cron_found
126
130
 
127
- status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
128
- crontab.each_line { |line| stdin.puts "#{line}" }
129
- end
131
+ write_crontab crontab
130
132
  Chef::Log.info("#{@new_resource} updated crontab entry")
131
133
  @new_resource.updated_by_last_action(true)
132
134
  else
133
- unless @cron_empty
134
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
135
- stdout.each { |line| crontab << line }
136
- end
137
- end
135
+ crontab = read_crontab unless @cron_empty
138
136
 
139
137
  crontab << newcron
140
138
 
141
- status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
142
- crontab.each_line { |line| stdin.puts "#{line}" }
143
- end
139
+ write_crontab crontab
144
140
  Chef::Log.info("#{@new_resource} added crontab entry")
145
141
  @new_resource.updated_by_last_action(true)
146
142
  end
@@ -150,27 +146,26 @@ class Chef
150
146
  if @cron_exists
151
147
  crontab = String.new
152
148
  cron_found = false
153
- status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
154
- stdout.each_line do |line|
155
- case line.chomp
156
- when "# Chef Name: #{@new_resource.name}"
157
- cron_found = true
149
+ read_crontab.each_line do |line|
150
+ case line.chomp
151
+ when "# Chef Name: #{@new_resource.name}"
152
+ cron_found = true
153
+ next
154
+ when ENV_PATTERN
155
+ next if cron_found
156
+ when CRON_PATTERN
157
+ if cron_found
158
+ cron_found = false
158
159
  next
159
- when CRON_PATTERN
160
- if cron_found
161
- cron_found = false
162
- next
163
- end
164
- else
165
- next if cron_found
166
160
  end
167
- crontab << line
161
+ else
162
+ # We've got a Chef comment with no following crontab line
163
+ cron_found = false
168
164
  end
165
+ crontab << line
169
166
  end
170
167
 
171
- status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
172
- crontab.each_line { |line| stdin.puts "#{line}" }
173
- end
168
+ write_crontab crontab
174
169
  Chef::Log.info("#{@new_resource} deleted crontab entry")
175
170
  @new_resource.updated_by_last_action(true)
176
171
  end
@@ -179,13 +174,32 @@ class Chef
179
174
  private
180
175
 
181
176
  def set_environment_var(attr_name, attr_value)
182
- method_name = attr_name.downcase.to_sym
183
- if CRON_ATTRIBUTES.include?(method_name)
184
- @current_resource.send(method_name, attr_value)
177
+ if %w(MAILTO PATH SHELL HOME).include?(attr_name)
178
+ @current_resource.send(attr_name.downcase.to_sym, attr_value)
185
179
  else
186
180
  @current_resource.environment(@current_resource.environment.merge(attr_name => attr_value))
187
181
  end
188
182
  end
183
+
184
+ def read_crontab
185
+ crontab = nil
186
+ status = popen4("crontab -l -u #{@new_resource.user}") do |pid, stdin, stdout, stderr|
187
+ crontab = stdout.read
188
+ end
189
+ if status.exitstatus > 1
190
+ raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
191
+ end
192
+ crontab
193
+ end
194
+
195
+ def write_crontab(crontab)
196
+ status = popen4("crontab -u #{@new_resource.user} -", :waitlast => true) do |pid, stdin, stdout, stderr|
197
+ stdin.write crontab
198
+ end
199
+ if status.exitstatus > 0
200
+ raise Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: #{status.exitstatus}"
201
+ end
202
+ end
189
203
  end
190
204
  end
191
205
  end
@@ -19,165 +19,38 @@
19
19
  #
20
20
 
21
21
  require 'chef/log'
22
- require 'chef/mixin/command'
23
22
  require 'chef/provider'
24
23
 
25
24
  class Chef
26
25
  class Provider
27
26
  class Cron
28
27
  class Solaris < Chef::Provider::Cron
29
- include Chef::Mixin::Command
30
28
 
31
- CRON_PATTERN = /([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s([-0-9*,\/]+)\s(.*)/
29
+ private
32
30
 
33
- def initialize(new_resource, run_context)
34
- super(new_resource, run_context)
35
- @cron_exists = false
36
- @cron_empty = false
37
- end
38
- attr_accessor :cron_exists, :cron_empty
39
-
40
- def load_current_resource
41
- crontab_lines = []
42
- @current_resource = Chef::Resource::Cron.new(@new_resource.name)
43
- @current_resource.user(@new_resource.user)
44
- status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
45
- stdout.each_line { |line| crontab_lines << line }
46
- end
47
- if status.exitstatus > 1
48
- raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
49
- elsif status.exitstatus == 0
50
- cron_found = false
51
- crontab_lines.each do |line|
52
- case line.chomp
53
- when "# Chef Name: #{@new_resource.name}"
54
- Chef::Log.debug("#{@new_resource} found cron '#{@new_resource.name}'")
55
- cron_found = true
56
- @cron_exists = true
57
- next
58
- when /^(\S*)=(\S*)/
59
- set_environment_var($1, $2) if cron_found
60
- next
61
- when CRON_PATTERN
62
- if cron_found
63
- @current_resource.minute($1)
64
- @current_resource.hour($2)
65
- @current_resource.day($3)
66
- @current_resource.month($4)
67
- @current_resource.weekday($5)
68
- @current_resource.command($6)
69
- cron_found=false
70
- end
71
- next
72
- else
73
- next
74
- end
75
- end
76
- Chef::Log.debug("#{@new_resource} cron '#{@new_resource.name}' not found") unless @cron_exists
77
- elsif status.exitstatus == 1
78
- Chef::Log.debug("#{@new_resource} cron empty for '#{@new_resource.user}'")
79
- @cron_empty = true
80
- end
81
-
82
- @current_resource
83
- end
84
-
85
- def write_crontab(crontab)
86
- tempcron = Tempfile.new("chef-cron")
87
- tempcron << crontab
88
- tempcron.flush
89
- tempcron.chmod(0644)
90
- status = run_command(:command => "/usr/bin/crontab #{tempcron.path}",:user => @new_resource.user)
91
- if(status == 0)
92
- @new_resource.updated_by_last_action(true)
93
- else
94
- @new_resource.updated_by_last_action(false)
95
- end
96
- tempcron.close!
97
- return status
98
- end
99
-
100
- def action_create
101
- crontab = String.new
102
- newcron = String.new
103
- cron_found = false
104
-
105
- newcron << "# Chef Name: #{new_resource.name}\n"
106
- [ :mailto, :path, :shell, :home ].each do |v|
107
- newcron << "#{v.to_s.upcase}=#{@new_resource.send(v)}\n" if @new_resource.send(v)
108
- end
109
- @new_resource.environment.each do |name, value|
110
- newcron << "#{name}=#{value}\n"
111
- end
112
-
113
- newcron << "#{@new_resource.minute} #{@new_resource.hour} #{@new_resource.day} #{@new_resource.month} #{@new_resource.weekday} #{@new_resource.command}\n"
114
-
115
- if @cron_exists
116
- unless compare_cron
117
- Chef::Log.debug("#{@new_resource} skipping existing cron entry '#{@new_resource.name}'")
118
- return
119
- end
31
+ def read_crontab
32
+ crontab = nil
120
33
  status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
121
- stdout.each_line do |line|
122
- case line.chomp
123
- when "# Chef Name: #{@new_resource.name}"
124
- cron_found = true
125
- next
126
- when CRON_PATTERN
127
- if cron_found
128
- cron_found = false
129
- crontab << newcron
130
- next
131
- end
132
- else
133
- next if cron_found
134
- end
135
- crontab << line
136
- end
34
+ crontab = stdout.read
137
35
  end
138
-
139
- status = write_crontab(crontab)
140
- Chef::Log.info("#{@new_resource} updated crontab entry")
141
- else
142
- unless @cron_empty
143
- status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
144
- stdout.each { |line| crontab << line }
145
- end
36
+ if status.exitstatus > 1
37
+ raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status.exitstatus}"
146
38
  end
147
-
148
- crontab << newcron
149
- status = write_crontab(crontab)
150
- Chef::Log.info("#{@new_resource} added crontab entry")
39
+ crontab
151
40
  end
152
- end
153
41
 
154
- def action_delete
155
- if @cron_exists
156
- crontab = String.new
157
- cron_found = false
158
- status = popen4("crontab -l #{@new_resource.user}") do |pid, stdin, stdout, stderr|
159
- stdout.each_line do |line|
160
- case line.chomp
161
- when "# Chef Name: #{@new_resource.name}"
162
- cron_found = true
163
- next
164
- when CRON_PATTERN
165
- if cron_found
166
- cron_found = false
167
- next
168
- end
169
- else
170
- next if cron_found
171
- end
172
- crontab << line
173
- end
42
+ def write_crontab(crontab)
43
+ tempcron = Tempfile.new("chef-cron")
44
+ tempcron << crontab
45
+ tempcron.flush
46
+ tempcron.chmod(0644)
47
+ status = run_command(:command => "/usr/bin/crontab #{tempcron.path}",:user => @new_resource.user)
48
+ tempcron.close!
49
+ if status.exitstatus > 0
50
+ raise Chef::Exceptions::Cron, "Error updating state of #{@new_resource.name}, exit: #{status.exitstatus}"
174
51
  end
175
-
176
- status = write_crontab(crontab)
177
- Chef::Log.info("#{@new_resource} deleted crontab entry")
178
52
  end
179
53
  end
180
54
  end
181
55
  end
182
56
  end
183
- end
@@ -42,6 +42,7 @@ class Chef
42
42
  end
43
43
 
44
44
  def load_current_resource
45
+ @scm_provider.load_current_resource
45
46
  @release_path = @new_resource.deploy_to + "/releases/#{release_slug}"
46
47
  end
47
48
 
@@ -205,7 +206,6 @@ class Chef
205
206
  end
206
207
 
207
208
  def update_cached_repo
208
- @scm_provider.load_current_resource
209
209
  if @new_resource.svn_force_export
210
210
  svn_force_export
211
211
  else
@@ -78,10 +78,7 @@ class Chef
78
78
 
79
79
  def groupadd_options
80
80
  opts = ''
81
- case node[:platform]
82
- when "centos", "redhat", "scientific", "fedora"
83
- opts << " -r" if @new_resource.system
84
- end
81
+ opts << " -r" if @new_resource.system
85
82
  opts
86
83
  end
87
84
 
@@ -51,7 +51,7 @@ class Chef
51
51
 
52
52
  def action_create
53
53
  unless @current_resource.exists
54
- command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --metadata=#{@new_resource.metadata} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.join(" ")}"
54
+ command = "yes | mdadm --create #{@new_resource.raid_device} --chunk=#{@new_resource.chunk} --level #{@new_resource.level} --metadata=#{@new_resource.metadata} --bitmap=#{@new_resource.bitmap} --raid-devices #{@new_resource.devices.length} #{@new_resource.devices.join(" ")}"
55
55
  Chef::Log.debug("#{@new_resource} mdadm command: #{command}")
56
56
  #pid, stdin, stdout, stderr = popen4(command)
57
57
  shell_out!(command)