Update cookbooks and add wordpress cookbook
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
# Library:: helper
|
||||
#
|
||||
# Author:: Julian C. Dunn <jdunn@chef.io>
|
||||
# Author:: Justin Schuhmann <jmschu02@gmail.com>
|
||||
#
|
||||
# Copyright 2013, Chef Software, Inc.
|
||||
#
|
||||
@@ -23,11 +24,17 @@ module Opscode
|
||||
module IIS
|
||||
# Contains functions that are used throughout this cookbook
|
||||
module Helper
|
||||
@iis_version = nil
|
||||
|
||||
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
||||
require 'chef/win32/version'
|
||||
require 'win32/registry'
|
||||
end
|
||||
|
||||
require 'rexml/document'
|
||||
require 'chef/mixin/shell_out'
|
||||
|
||||
include Chef::Mixin::ShellOut
|
||||
include REXML
|
||||
include Windows::Helper
|
||||
|
||||
@@ -82,6 +89,15 @@ module Opscode
|
||||
"#{node['iis']['home']}\\appcmd.exe"
|
||||
end
|
||||
end
|
||||
|
||||
def iis_version
|
||||
if @iis_version.nil?
|
||||
version_string = Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\InetStp').read('VersionString')[1]
|
||||
version_string.slice! 'Version '
|
||||
@iis_version = version_string
|
||||
end
|
||||
@iis_version
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,57 +5,59 @@ if defined?(ChefSpec)
|
||||
end
|
||||
|
||||
[:config, :add, :delete].each do |action|
|
||||
self.class.send(:define_method, "#{action}_iis_app", proc do |app_name|
|
||||
self.class.send(:define_method, "#{action}_iis_app", proc do |app_name|
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:iis_app, action, app_name)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
[:config].each do |action|
|
||||
self.class.send(:define_method, "#{action}_iis_lock", proc do |section|
|
||||
self.class.send(:define_method, "#{action}_iis_lock", proc do |section|
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:iis_lock, action, section)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
[:add, :delete].each do |action|
|
||||
[:add, :delete, :install, :uninstall].each do |action|
|
||||
self.class.send(:define_method, "#{action}_iis_module", proc do |module_name|
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:iis_module, action, module_name)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
[:add, :config, :delete, :start, :stop, :restart, :recycle].each do |action|
|
||||
self.class.send(:define_method, "#{action}_iis_pool", proc do |pool_name|
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:iis_pool, action, pool_name)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
[:add, :delete, :start, :stop, :restart, :config].each do |action|
|
||||
self.class.send(:define_method, "#{action}_iis_site", proc do |site_name|
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:iis_site, action, site_name)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
[:config].each do |action|
|
||||
self.class.send(:define_method, "#{action}_iis_unlock", proc do |section|
|
||||
self.class.send(:define_method, "#{action}_iis_unlock", proc do |section|
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:iis_unlock, action, section)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
[:add, :config, :delete].each do |action|
|
||||
self.class.send(:define_method, "#{action}_iis_vdir", proc do |section|
|
||||
self.class.send(:define_method, "#{action}_iis_vdir", proc do |section|
|
||||
ChefSpec::Matchers::ResourceMatcher.new(:iis_vdir, action, section)
|
||||
end
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
define_method = (Gem.loaded_specs['chefspec'].version < Gem::Version.new('4.1.0')) ?
|
||||
ChefSpec::Runner.method(:define_runner_method) :
|
||||
ChefSpec.method(:define_matcher)
|
||||
if Gem.loaded_specs['chefspec'].version < Gem::Version.new('4.1.0')
|
||||
define_method = ChefSpec::Runner.method(:define_runner_method)
|
||||
else
|
||||
define_method = ChefSpec.method(:define_matcher)
|
||||
end
|
||||
|
||||
define_method.call :iis_app
|
||||
define_method.call :iis_config
|
||||
|
||||
117
cookbooks/iis/libraries/processors.rb
Normal file
117
cookbooks/iis/libraries/processors.rb
Normal file
@@ -0,0 +1,117 @@
|
||||
#
|
||||
# Cookbook Name:: iis
|
||||
# Library:: helper
|
||||
#
|
||||
# Author:: Justin Schuhmann <jmschu02@gmail.com>
|
||||
#
|
||||
# Copyright 2013, Chef Software, Inc.
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
module Opscode
|
||||
module IIS
|
||||
# Contains functions that are used throughout this cookbook
|
||||
module Processors
|
||||
def default_documents(default_document, default_documents_enabled, add = true, remove = true, specifier = '')
|
||||
cmd = shell_out! get_default_documents_command specifier
|
||||
return unless cmd.stderr.empty?
|
||||
xml = cmd.stdout
|
||||
doc = REXML::Document.new xml
|
||||
|
||||
is_new_default_documents_enabled = new_value?(doc.root, 'CONFIG/system.webServer-defaultDocument/@enabled', default_documents_enabled.to_s)
|
||||
current_default_documents = REXML::XPath.match(doc.root, 'CONFIG/system.webServer-defaultDocument/files/add/@value').map(&:value)
|
||||
cmd = default_documents_command specifier
|
||||
|
||||
if is_new_default_documents_enabled
|
||||
cmd << " /enabled:#{default_documents_enabled}"
|
||||
end
|
||||
|
||||
if add || remove
|
||||
default_document.each do |document|
|
||||
if !current_default_documents.include?(document) && add
|
||||
cmd << " /+files.[value='#{document}']"
|
||||
elsif current_default_documents.include?(document) && remove
|
||||
cmd << " /-files.[value='#{document}']"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if add && remove
|
||||
current_default_documents.each do |document|
|
||||
unless default_document.include? document
|
||||
cmd << " /-files.[value='#{document}']"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return unless cmd != default_documents_command(specifier)
|
||||
shell_out! cmd
|
||||
Chef::Log.info('Default Documents updated')
|
||||
@was_updated = true
|
||||
end
|
||||
|
||||
def mime_maps(new_resource_mime_maps, add = true, remove = true, specifier = '')
|
||||
# handles mime maps
|
||||
cmd = shell_out get_mime_map_command specifier
|
||||
return unless cmd.stderr.empty?
|
||||
xml = cmd.stdout
|
||||
doc = REXML::Document.new xml
|
||||
current_mime_maps = REXML::XPath.match(doc.root, 'CONFIG/system.webServer-staticContent/mimeMap').map { |x| "fileExtension='#{x.attribute 'fileExtension'}',mimeType='#{x.attribute 'mimeType'}'" }
|
||||
|
||||
cmd = mime_map_command specifier
|
||||
|
||||
if add || remove
|
||||
new_resource_mime_maps.each do |mime_map|
|
||||
if !current_mime_maps.include?(mime_map) && add
|
||||
cmd << " /+\"[#{mime_map}]\""
|
||||
elsif current_mime_maps.include?(mime_map) && remove
|
||||
cmd << " /-\"[#{mime_map}]\""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if add && remove
|
||||
current_mime_maps.each do |mime_map|
|
||||
unless new_resource_mime_maps.include? mime_map
|
||||
cmd << " /-\"[#{mime_map}]\""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return unless (cmd != mime_map_command(specifier))
|
||||
shell_out! cmd
|
||||
Chef::Log.info('mime maps updated')
|
||||
@was_updated = true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_default_documents_command(specifier = '')
|
||||
"#{appcmd(node)} list config #{specifier} /section:defaultDocument /config:* /xml"
|
||||
end
|
||||
|
||||
def default_documents_command(specifier = '')
|
||||
"#{appcmd(node)} set config #{specifier} /section:defaultDocument"
|
||||
end
|
||||
|
||||
def get_mime_map_command(specifier = '')
|
||||
"#{appcmd(node)} list config #{specifier} /section:staticContent /config:* /xml"
|
||||
end
|
||||
|
||||
def mime_map_command(specifier = '')
|
||||
"#{appcmd(node)} set config #{specifier} /section:staticContent"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user