diff --git a/README.md b/README.md index fa21926d..f665446a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ The following cookbooks provided by Opscode are required as noted: Attributes ---------- * `node['windows']['allow_pending_reboots']` - used to configure the `WindowsRebootHandler` (via the `windows::reboot_handler` recipe) to act on pending reboots. default is true (ie act on pending reboots). The value of this attribute only has an effect if the `windows::reboot_handler` is in a node's run list. +* `node['windows']['allow_reboot_on_failure']` - used to register the `WindowsRebootHandler` (via the `windows::reboot_handler` recipe) as an exception handler too to act on reboots not only at the end of successful Chef runs, but even at the end of failed runs. default is false (ie reboot only after successful runs). The value of this attribute only has an effect if the `windows::reboot_handler` is in a node's run list. Resource/Provider @@ -115,6 +116,7 @@ servermanagercmd -query #### Providers - **Chef::Provider::WindowsFeature::DISM**: Uses Deployment Image Servicing and Management (DISM) to manage roles/features. - **Chef::Provider::WindowsFeature::ServerManagerCmd**: Uses Server Manager to manage roles/features. +- **Chef::Provider::WindowsFeaturePowershell**: Uses Powershell to manage roles/features. (see [COOK-3714](https://tickets.opscode.com/browse/COOK-3714) #### Examples Enable the node as a DHCP Server @@ -562,7 +564,7 @@ end Exception/Report Handlers ------------------------- ### WindowsRebootHandler -Required reboots are a necessary evil of configuring and managing Windows nodes. This report handler (ie fires at the end of successful Chef runs) acts on requested (Chef initiated) or pending (as determined by the OS per configuration action we performed) reboots. The `allow_pending_reboots` initialization argument should be set to false if you do not want the handler to automatically reboot a node if it has been determined a reboot is pending. Reboots can still be requested explicitly via the `windows_reboot` LWRP. +Required reboots are a necessary evil of configuring and managing Windows nodes. This report handler (ie fires at the end of Chef runs) acts on requested (Chef initiated) or pending (as determined by the OS per configuration action we performed) reboots. The `allow_pending_reboots` initialization argument should be set to false if you do not want the handler to automatically reboot a node if it has been determined a reboot is pending. Reboots can still be requested explicitly via the `windows_reboot` LWRP. ### Initialization Arguments - `allow_pending_reboots`: indicator on whether the handler should act on a the Window's 'pending reboot' state. default is true @@ -637,6 +639,8 @@ override_attributes( This will still allow a reboot to be explicitly requested via the `windows_reboot` LWRP. +By default, the handler will only be registered as a report handler, meaning that it will only fire at the end of successful Chef runs. If the run fails, pending or requested reboots will be ignored. This can lead to a situation where some package was installed and notified a reboot request via the `windows_reboot` LWRP, and then the run fails for some unrelated reason, and the reboot request gets dropped because the resource that notified the reboot request will already be up-to-date at the next run and will not request a reboot again, and thus the requested reboot will never be performed. To change this behavior and register the handler as an exception handler that fires at the end of failed runs too, override `node['windows']['allow_reboot_on_failure']` and set the value to true. + License & Authors ----------------- diff --git a/attributes/default.rb b/attributes/default.rb index c4e5919c..26f5c965 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -19,5 +19,6 @@ # default['windows']['allow_pending_reboots'] = true +default['windows']['allow_reboot_on_failure'] = false default['windows']['rubyzipversion'] = nil default['windows']['reboot_timeout'] = 60 \ No newline at end of file diff --git a/libraries/matchers.rb b/libraries/matchers.rb index ba00ebd7..baabee3c 100644 --- a/libraries/matchers.rb +++ b/libraries/matchers.rb @@ -1,4 +1,16 @@ if defined?(ChefSpec) + ChefSpec::Runner.define_runner_method :windows_package + ChefSpec::Runner.define_runner_method :windows_feature + ChefSpec::Runner.define_runner_method :windows_task + ChefSpec::Runner.define_runner_method :windows_path + ChefSpec::Runner.define_runner_method :windows_batch + ChefSpec::Runner.define_runner_method :windows_pagefile + ChefSpec::Runner.define_runner_method :windows_zipfile + ChefSpec::Runner.define_runner_method :windows_shortcut + ChefSpec::Runner.define_runner_method :windows_auto_run + ChefSpec::Runner.define_runner_method :windows_printer + ChefSpec::Runner.define_runner_method :windows_printer_port + ChefSpec::Runner.define_runner_method :windows_reboot # # Assert that a +windows_package+ resource exists in the Chef run with the @@ -444,7 +456,7 @@ def cancel_windows_reboot(resource_name) ChefSpec::Matchers::ResourceMatcher.new(:windows_reboot, :cancel, resource_name) end - def create_windows_shortcut(resource_name) - ChefSpec::Matchers::ResourceMatcher.new(:windows_shortcut, :create, resource_name) + def create_windows_share(resource_name) + ChefSpec::Matchers::ResourceMatcher.new(:windows_share, :create, resource_name) end end diff --git a/libraries/windows_helper.rb b/libraries/windows_helper.rb index 9161e10a..ca6a4bc7 100644 --- a/libraries/windows_helper.rb +++ b/libraries/windows_helper.rb @@ -28,7 +28,7 @@ module Helper # returns windows friendly version of the provided path, # ensures backslashes are used everywhere def win_friendly_path(path) - path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR) if path + path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR || '\\') if path end # account for Window's wacky File System Redirector diff --git a/providers/auto_run.rb b/providers/auto_run.rb index a40cbfd9..6d670340 100644 --- a/providers/auto_run.rb +++ b/providers/auto_run.rb @@ -17,6 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +use_inline_resources if defined?(use_inline_resources) action :create do windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do diff --git a/providers/batch.rb b/providers/batch.rb index 9aa347cf..7d4b5a4e 100644 --- a/providers/batch.rb +++ b/providers/batch.rb @@ -17,6 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +use_inline_resources if defined?(use_inline_resources) require 'tempfile' require 'chef/resource/execute' diff --git a/providers/path.rb b/providers/path.rb index c37657cd..d297aec9 100644 --- a/providers/path.rb +++ b/providers/path.rb @@ -17,6 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +use_inline_resources if defined?(use_inline_resources) action :add do env "path" do diff --git a/providers/printer.rb b/providers/printer.rb index 89cec4a3..3dd976c7 100644 --- a/providers/printer.rb +++ b/providers/printer.rb @@ -17,6 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +use_inline_resources if defined?(use_inline_resources) # Support whyrun def whyrun_supported? diff --git a/providers/printer_port.rb b/providers/printer_port.rb index fe01db52..d2666eca 100644 --- a/providers/printer_port.rb +++ b/providers/printer_port.rb @@ -17,6 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +use_inline_resources if defined?(use_inline_resources) # Support whyrun def whyrun_supported? diff --git a/providers/share.rb b/providers/share.rb new file mode 100644 index 00000000..00eca65c --- /dev/null +++ b/providers/share.rb @@ -0,0 +1,56 @@ +# +# Author:: Venkat Naidu (naiduvenkat@gmail.com) +# Cookbook Name:: windows +# Provider:: share +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +require 'chef/mixin/shell_out' + +include Chef::Mixin::ShellOut +include Windows::Helper + +def load_current_resource + @current_resource = Chef::Resource::WindowsShare.new(@new_resource.name) + @current_resource.name(@new_resource.name) + @current_resource.user(@new_resource.user) + @current_resource.path(@new_resource.path) + @current_resource.access(@new_resource.access) + + @current_resource +end + +action :create do + cmd = "net share " + @current_resource.name + "=" + @current_resource.path + " /GRANT:" + @current_resource.user + ",#{access_type_template}" + shell_out!(cmd) + @new_resource.updated_by_last_action(true) + Chef::Log.info("Share created") +end + +def access_type_template + case access_type + when :read + "READ" + when :change + "CHANGE" + when :full + "FULL" + else + end +end + +def access_type + @current_resource.access +end diff --git a/recipes/reboot_handler.rb b/recipes/reboot_handler.rb index 2e55b91f..6adb1193 100644 --- a/recipes/reboot_handler.rb +++ b/recipes/reboot_handler.rb @@ -27,6 +27,6 @@ chef_handler 'WindowsRebootHandler' do source "#{node['chef_handler']['handler_path']}/windows_reboot_handler.rb" arguments node['windows']['allow_pending_reboots'] - supports :report => true, :exception => false + supports :report => true, :exception => node['windows']['allow_reboot_on_failure'] action :enable end diff --git a/resources/share.rb b/resources/share.rb new file mode 100644 index 00000000..75a97ec2 --- /dev/null +++ b/resources/share.rb @@ -0,0 +1,23 @@ +uthor:: Venkat Naidu () +# Cookbook Name:: windows +# Resource:: share +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +actions :create, :delete +attribute :name, :kind_of => String, :name_attribute => true +attribute :path, :kind_of => String +attribute :access, :kind_of => Symbol, :default => :read, :equal_to => [:read, :chage, :full] +attribute :user, :kind_of => String +