chef 0.10.2 → 0.10.4.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/distro/common/html/chef-client.8.html +4 -4
  2. data/distro/common/html/knife-cookbook.1.html +5 -3
  3. data/distro/common/html/knife-node.1.html +4 -4
  4. data/distro/common/man/man1/knife-cookbook.1 +5 -1
  5. data/distro/common/man/man1/knife-node.1 +1 -1
  6. data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
  7. data/distro/common/markdown/man1/knife-cookbook.mkd +7 -0
  8. data/distro/common/markdown/man1/knife-node.mkd +4 -3
  9. data/distro/common/markdown/man1/knife-ssh.mkd +2 -0
  10. data/lib/chef/application.rb +1 -0
  11. data/lib/chef/cookbook_loader.rb +18 -0
  12. data/lib/chef/cookbook_uploader.rb +1 -1
  13. data/lib/chef/data_bag.rb +14 -2
  14. data/lib/chef/data_bag_item.rb +8 -2
  15. data/lib/chef/encrypted_data_bag_item.rb +19 -6
  16. data/lib/chef/environment.rb +12 -6
  17. data/lib/chef/exceptions.rb +1 -0
  18. data/lib/chef/knife.rb +0 -28
  19. data/lib/chef/knife/bootstrap.rb +7 -0
  20. data/lib/chef/knife/bootstrap/archlinux-gems.erb +14 -12
  21. data/lib/chef/knife/bootstrap/centos5-gems.erb +8 -5
  22. data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -0
  23. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +16 -9
  24. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -3
  25. data/lib/chef/knife/client_bulk_delete.rb +28 -6
  26. data/lib/chef/knife/cookbook_site_install.rb +2 -2
  27. data/lib/chef/knife/cookbook_upload.rb +71 -0
  28. data/lib/chef/knife/core/bootstrap_context.rb +13 -3
  29. data/lib/chef/knife/core/cookbook_scm_repo.rb +2 -3
  30. data/lib/chef/knife/core/node_presenter.rb +5 -2
  31. data/lib/chef/knife/help.rb +13 -12
  32. data/lib/chef/knife/help_topics.rb +4 -0
  33. data/lib/chef/knife/ssh.rb +25 -4
  34. data/lib/chef/mixin/create_path.rb +3 -2
  35. data/lib/chef/mixin/get_source_from_package.rb +42 -0
  36. data/lib/chef/mixin/language.rb +8 -11
  37. data/lib/chef/monkey_patches/numeric.rb +9 -1
  38. data/lib/chef/monkey_patches/string.rb +21 -0
  39. data/lib/chef/platform.rb +2 -1
  40. data/lib/chef/provider.rb +1 -1
  41. data/lib/chef/provider/git.rb +16 -3
  42. data/lib/chef/provider/group/suse.rb +53 -0
  43. data/lib/chef/provider/mount/mount.rb +28 -20
  44. data/lib/chef/provider/package/apt.rb +39 -24
  45. data/lib/chef/provider/package/dpkg.rb +5 -2
  46. data/lib/chef/provider/package/easy_install.rb +2 -2
  47. data/lib/chef/provider/package/freebsd.rb +5 -2
  48. data/lib/chef/provider/package/macports.rb +4 -4
  49. data/lib/chef/provider/package/rpm.rb +4 -1
  50. data/lib/chef/provider/package/rubygems.rb +3 -0
  51. data/lib/chef/provider/package/solaris.rb +3 -0
  52. data/lib/chef/provider/package/yum-dump.py +239 -81
  53. data/lib/chef/provider/package/yum.rb +977 -110
  54. data/lib/chef/provider/package/zypper.rb +20 -3
  55. data/lib/chef/provider/remote_directory.rb +0 -1
  56. data/lib/chef/provider/service/arch.rb +35 -28
  57. data/lib/chef/provider/service/systemd.rb +102 -0
  58. data/lib/chef/provider/service/upstart.rb +8 -2
  59. data/lib/chef/providers.rb +2 -0
  60. data/lib/chef/resource.rb +31 -2
  61. data/lib/chef/resource/git.rb +9 -0
  62. data/lib/chef/resource/mount.rb +1 -2
  63. data/lib/chef/resource/yum_package.rb +20 -0
  64. data/lib/chef/rest.rb +1 -1
  65. data/lib/chef/role.rb +1 -1
  66. data/lib/chef/run_context.rb +3 -3
  67. data/lib/chef/runner.rb +15 -2
  68. data/lib/chef/shell_out.rb +1 -1
  69. data/lib/chef/shell_out/windows.rb +2 -2
  70. data/lib/chef/solr_query.rb +1 -1
  71. data/lib/chef/tasks/chef_repo.rake +1 -1
  72. data/lib/chef/version.rb +1 -1
  73. metadata +425 -441
@@ -78,9 +78,18 @@ class Chef
78
78
 
79
79
  @current_resource
80
80
  end
81
+
82
+ #Gets the zypper Version from command output (Returns Floating Point number)
83
+ def zypper_version()
84
+ `zypper -V 2>&1`.scan(/\d+/).join(".").to_f
85
+ end
81
86
 
82
87
  def install_package(name, version)
83
- if version
88
+ if zypper_version < 1.0
89
+ run_command(
90
+ :command => "zypper install -y #{name}"
91
+ )
92
+ elsif version
84
93
  run_command(
85
94
  :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}"
86
95
  )
@@ -92,7 +101,11 @@ class Chef
92
101
  end
93
102
 
94
103
  def upgrade_package(name, version)
95
- if version
104
+ if zypper_version < 1.0
105
+ run_command(
106
+ :command => "zypper install -y #{name}"
107
+ )
108
+ elsif version
96
109
  run_command(
97
110
  :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}"
98
111
  )
@@ -104,7 +117,11 @@ class Chef
104
117
  end
105
118
 
106
119
  def remove_package(name, version)
107
- if version
120
+ if zypper_version < 1.0
121
+ run_command(
122
+ :command => "zypper remove -y #{name}"
123
+ )
124
+ elsif version
108
125
  run_command(
109
126
  :command => "zypper -n --no-gpg-checks remove #{name}=#{version}"
110
127
  )
@@ -45,7 +45,6 @@ class Chef
45
45
  end
46
46
  purge_unmanaged_files(files_to_purge)
47
47
  Chef::Log.info("#{@new_resource} created")
48
- @new_resource.updated_by_last_action(true)
49
48
  end
50
49
 
51
50
  def action_create_if_missing
@@ -20,16 +20,16 @@ require 'chef/provider/service/init'
20
20
  require 'chef/mixin/command'
21
21
 
22
22
  class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
23
-
23
+
24
24
  def initialize(new_resource, run_context)
25
25
  super
26
26
  @init_command = "/etc/rc.d/#{@new_resource.service_name}"
27
27
  end
28
-
28
+
29
29
  def load_current_resource
30
-
30
+
31
31
  raise Chef::Exceptions::Service unless ::File.exists?("/etc/rc.conf")
32
- raise Chef::Exceptions::Service unless ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/)
32
+ raise Chef::Exceptions::Service unless ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/m)
33
33
 
34
34
  super
35
35
 
@@ -38,38 +38,46 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
38
38
  @current_resource
39
39
  end
40
40
 
41
+ # Get list of all daemons from the file '/etc/rc.conf'.
42
+ # Mutiple lines and background form are supported. Example:
43
+ # DAEMONS=(\
44
+ # foobar \
45
+ # @example \
46
+ # !net \
47
+ # )
41
48
  def daemons
42
49
  entries = []
43
- if ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/)
44
- entries += $1.split(" ") if $1.length > 0
50
+ if ::File.read("/etc/rc.conf").match(/DAEMONS=\((.*)\)/m)
51
+ entries += $1.gsub(/\\?[\r\n]/, ' ').gsub(/# *[^ ]+/,' ').split(' ') if $1.length > 0
45
52
  end
46
-
53
+
47
54
  yield(entries) if block_given?
48
-
55
+
49
56
  entries
50
57
  end
51
-
58
+
59
+ # FIXME: Multiple entries of DAEMONS will cause very bad results :)
52
60
  def update_daemons(entries)
53
- content = ::File.read("/etc/rc.conf").gsub(/DAEMONS=\((.*)\)/, "DAEMONS=(#{entries.join(' ')})")
61
+ content = ::File.read("/etc/rc.conf").gsub(/DAEMONS=\((.*)\)/m, "DAEMONS=(#{entries.join(' ')})")
54
62
  ::File.open("/etc/rc.conf", "w") do |f|
55
63
  f.write(content)
56
64
  end
57
65
  end
58
-
66
+
59
67
  def enable_service()
60
68
  new_daemons = []
61
69
  entries = daemons
62
-
63
- if entries.include?(new_resource.service_name)
64
- # exists and already enabled
65
- new_daemons += entries
70
+
71
+ if entries.include?(new_resource.service_name) or entries.include?("@#{new_resource.service_name}")
72
+ # exists and already enabled (or already enabled as a background service)
73
+ # new_daemons += entries
66
74
  else
67
75
  if entries.include?("!#{new_resource.service_name}")
68
76
  # exists but disabled
69
77
  entries.each do |daemon|
70
- if daemon == "!#{new_resource.service_name}"
78
+ if daemon == "!#{new_resource.service_name}"
71
79
  new_daemons << new_resource.service_name
72
- else
80
+ else
73
81
  new_daemons << daemon
74
82
  end
75
83
  end
@@ -78,32 +86,31 @@ class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
78
86
  new_daemons += entries
79
87
  new_daemons << new_resource.service_name
80
88
  end
89
+ update_daemons(new_daemons)
81
90
  end
82
-
83
- update_daemons(new_daemons)
84
91
  end
85
-
92
+
86
93
  def disable_service()
87
94
  new_daemons = []
88
95
  entries = daemons
89
-
96
+
90
97
  if entries.include?("!#{new_resource.service_name}")
91
98
  # exists and disabled
92
- new_daemons += entries
99
+ # new_daemons += entries
93
100
  else
94
- if entries.include?(new_resource.service_name)
95
- # exists but enabled
101
+ if entries.include?(new_resource.service_name) or entries.include?("@#{new_resource.service_name}")
102
+ # exists but enabled (or enabled as a back-ground service)
103
+ # FIXME: Does arch support !@foobar ?
96
104
  entries.each do |daemon|
97
- if daemon == new_resource.service_name
105
+ if [new_resource.service_name, "@#{new_resource.service_name}"].include?(daemon)
98
106
  new_daemons << "!#{new_resource.service_name}"
99
- else
107
+ else
100
108
  new_daemons << daemon
101
109
  end
102
110
  end
103
111
  end
112
+ update_daemons(new_daemons)
104
113
  end
105
-
106
- update_daemons(new_daemons)
107
114
  end
108
115
 
109
116
  end
@@ -0,0 +1,102 @@
1
+ #
2
+ # Author:: Stephen Haynes (<sh@nomitor.com>)
3
+ # Copyright:: Copyright (c) 2011 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/provider/service'
20
+ require 'chef/provider/service/simple'
21
+ require 'chef/mixin/command'
22
+
23
+ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple
24
+ def load_current_resource
25
+ @current_resource = Chef::Resource::Service.new(@new_resource.name)
26
+ @current_resource.service_name(@new_resource.service_name)
27
+
28
+ if @new_resource.status_command
29
+ Chef::Log.debug("#{@new_resource} you have specified a status command, running..")
30
+
31
+ begin
32
+ if run_command_with_systems_locale(:command => @new_resource.status_command) == 0
33
+ @current_resource.running(true)
34
+ end
35
+ rescue Chef::Exceptions::Exec
36
+ @current_resource.running(false)
37
+ nil
38
+ end
39
+ else
40
+ @current_resource.running(is_active?)
41
+ end
42
+
43
+ @current_resource.enabled(is_enabled?)
44
+ @current_resource
45
+ end
46
+
47
+ def start_service
48
+ if @current_resource.running
49
+ Chef::Log.debug("#{@new_resource} already running, not starting")
50
+ else
51
+ if @new_resource.start_command
52
+ super
53
+ else
54
+ run_command_with_systems_locale(:command => "/bin/systemctl start #{@new_resource.service_name}")
55
+ end
56
+ end
57
+ end
58
+
59
+ def stop_service
60
+ unless @current_resource.running
61
+ Chef::Log.debug("#{@new_resource} not running, not stopping")
62
+ else
63
+ if @new_resource.stop_command
64
+ super
65
+ else
66
+ run_command_with_systems_locale(:command => "/bin/systemctl stop #{@new_resource.service_name}")
67
+ end
68
+ end
69
+ end
70
+
71
+ def restart_service
72
+ if @new_resource.restart_command
73
+ super
74
+ else
75
+ run_command_with_systems_locale(:command => "/bin/systemctl restart #{@new_resource.service_name}")
76
+ end
77
+ end
78
+
79
+ def reload_service
80
+ if @new_resource.reload_command
81
+ super
82
+ else
83
+ run_command_with_systems_locale(:command => "/bin/systemctl reload #{@new_resource.service_name}")
84
+ end
85
+ end
86
+
87
+ def enable_service
88
+ run_command_with_systems_locale(:command => "/bin/systemctl enable #{@new_resource.service_name}")
89
+ end
90
+
91
+ def disable_service
92
+ run_command_with_systems_locale(:command => "/bin/systemctl disable #{@new_resource.service_name}")
93
+ end
94
+
95
+ def is_active?
96
+ run_command_with_systems_locale({:command => "/bin/systemctl is-active #{@new_resource.service_name}", :ignore_failure => true}) == 0
97
+ end
98
+
99
+ def is_enabled?
100
+ run_command_with_systems_locale({:command => "/bin/systemctl is-enabled #{@new_resource.service_name}", :ignore_failure => true}) == 0
101
+ end
102
+ end
@@ -140,8 +140,14 @@ class Chef
140
140
  def restart_service
141
141
  if @new_resource.restart_command
142
142
  super
143
- else
144
- run_command_with_systems_locale(:command => "/sbin/restart #{@new_resource.service_name}")
143
+ # Upstart always provides restart functionality so we don't need to mimic it with stop/sleep/start.
144
+ # Older versions of upstart would fail on restart if the service was currently stopped, check for that. LP:430883
145
+ else @new_resource.supports[:restart]
146
+ if @current_resource.running
147
+ run_command_with_systems_locale(:command => "/sbin/restart #{@new_resource.service_name}")
148
+ else
149
+ start_service
150
+ end
145
151
  end
146
152
  end
147
153
 
@@ -69,6 +69,7 @@ require 'chef/provider/service/init'
69
69
  require 'chef/provider/service/insserv'
70
70
  require 'chef/provider/service/redhat'
71
71
  require 'chef/provider/service/simple'
72
+ require 'chef/provider/service/systemd'
72
73
  require 'chef/provider/service/upstart'
73
74
  require 'chef/provider/service/windows'
74
75
  require 'chef/provider/service/solaris'
@@ -83,6 +84,7 @@ require 'chef/provider/group/dscl'
83
84
  require 'chef/provider/group/gpasswd'
84
85
  require 'chef/provider/group/groupadd'
85
86
  require 'chef/provider/group/pw'
87
+ require 'chef/provider/group/suse'
86
88
  require 'chef/provider/group/usermod'
87
89
  require 'chef/provider/group/windows'
88
90
 
@@ -87,6 +87,8 @@ F
87
87
  attr_accessor :recipe_name
88
88
  attr_accessor :enclosing_provider
89
89
  attr_accessor :source_line
90
+ attr_accessor :retries
91
+ attr_accessor :retry_delay
90
92
 
91
93
  attr_reader :updated
92
94
 
@@ -112,6 +114,8 @@ F
112
114
  @updated_by_last_action = false
113
115
  @supports = {}
114
116
  @ignore_failure = false
117
+ @retries = 0
118
+ @retry_delay = 2
115
119
  @not_if = nil
116
120
  @not_if_args = {}
117
121
  @only_if = nil
@@ -224,6 +228,22 @@ F
224
228
  )
225
229
  end
226
230
 
231
+ def retries(arg=nil)
232
+ set_or_return(
233
+ :retries,
234
+ arg,
235
+ :kind_of => Integer
236
+ )
237
+ end
238
+
239
+ def retry_delay(arg=nil)
240
+ set_or_return(
241
+ :retry_delay,
242
+ arg,
243
+ :kind_of => Integer
244
+ )
245
+ end
246
+
227
247
  def epic_fail(arg=nil)
228
248
  ignore_failure(arg)
229
249
  end
@@ -468,8 +488,8 @@ F
468
488
  set_or_return(attr_name.to_sym, arg, validation_opts)
469
489
  end
470
490
  end
471
-
472
- def build_from_file(cookbook_name, filename)
491
+
492
+ def build_from_file(cookbook_name, filename, run_context)
473
493
  rname = filename_to_qualified_string(cookbook_name, filename)
474
494
 
475
495
  # Add log entry if we override an existing light-weight resource.
@@ -490,6 +510,12 @@ F
490
510
 
491
511
  class << cls
492
512
  include Chef::Mixin::FromFile
513
+
514
+ attr_accessor :run_context
515
+
516
+ def node
517
+ self.run_context.node
518
+ end
493
519
 
494
520
  def actions_to_create
495
521
  @actions_to_create
@@ -500,6 +526,9 @@ F
500
526
  end
501
527
  end
502
528
 
529
+ # set the run context in the class instance variable
530
+ cls.run_context = run_context
531
+
503
532
  # load resource definition from file
504
533
  cls.class_from_file(filename)
505
534
 
@@ -26,6 +26,15 @@ class Chef
26
26
  super
27
27
  @resource_name = :git
28
28
  @provider = Chef::Provider::Git
29
+ @additional_remotes = Hash[]
30
+ end
31
+
32
+ def additional_remotes(arg=nil)
33
+ set_or_return(
34
+ :additional_remotes,
35
+ arg,
36
+ :kind_of => Hash
37
+ )
29
38
  end
30
39
 
31
40
  alias :branch :revision
@@ -74,8 +74,7 @@ class Chef
74
74
 
75
75
  def options(arg=nil)
76
76
  if arg.is_a?(String)
77
- arg.gsub!(/,/, ' ')
78
- converted_arg = arg.split(/ /)
77
+ converted_arg = arg.gsub(/,/, ' ').split(/ /)
79
78
  else
80
79
  converted_arg = arg
81
80
  end
@@ -27,6 +27,8 @@ class Chef
27
27
  super
28
28
  @resource_name = :yum_package
29
29
  @provider = Chef::Provider::Package::Yum
30
+ @flush_cache = { :before => false, :after => false }
31
+ @allow_downgrade = false
30
32
  end
31
33
 
32
34
  # Install a specific arch
@@ -38,6 +40,24 @@ class Chef
38
40
  )
39
41
  end
40
42
 
43
+ def flush_cache(args={})
44
+ if args.is_a? Array
45
+ args.each { |arg| @flush_cache[arg] = true }
46
+ elsif args.any?
47
+ @flush_cache = args
48
+ else
49
+ @flush_cache
50
+ end
51
+ end
52
+
53
+ def allow_downgrade(arg=nil)
54
+ set_or_return(
55
+ :allow_downgrade,
56
+ arg,
57
+ :kind_of => [ TrueClass, FalseClass ]
58
+ )
59
+ end
60
+
41
61
  end
42
62
  end
43
63
  end