madscience 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.madscience_gem_location +0 -0
  4. data/Cheffile +9 -0
  5. data/Cheffile.lock +34 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +9 -0
  8. data/README.md +126 -0
  9. data/Rakefile +1 -0
  10. data/TODO +17 -0
  11. data/bin/madscience +90 -0
  12. data/cookbooks/apt/CHANGELOG.md +183 -0
  13. data/cookbooks/apt/README.md +255 -0
  14. data/cookbooks/apt/attributes/default.rb +29 -0
  15. data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
  16. data/cookbooks/apt/libraries/helpers.rb +49 -0
  17. data/cookbooks/apt/libraries/matchers.rb +17 -0
  18. data/cookbooks/apt/libraries/network.rb +31 -0
  19. data/cookbooks/apt/metadata.json +54 -0
  20. data/cookbooks/apt/metadata.rb +34 -0
  21. data/cookbooks/apt/providers/preference.rb +63 -0
  22. data/cookbooks/apt/providers/repository.rb +150 -0
  23. data/cookbooks/apt/recipes/cacher-client.rb +81 -0
  24. data/cookbooks/apt/recipes/cacher-ng.rb +43 -0
  25. data/cookbooks/apt/recipes/default.rb +91 -0
  26. data/cookbooks/apt/resources/preference.rb +32 -0
  27. data/cookbooks/apt/resources/repository.rb +43 -0
  28. data/cookbooks/apt/templates/debian-6.0/acng.conf.erb +173 -0
  29. data/cookbooks/apt/templates/default/01proxy.erb +5 -0
  30. data/cookbooks/apt/templates/default/acng.conf.erb +275 -0
  31. data/cookbooks/apt/templates/ubuntu-10.04/acng.conf.erb +269 -0
  32. data/cookbooks/chef_handler/CHANGELOG.md +44 -0
  33. data/cookbooks/chef_handler/README.md +103 -0
  34. data/cookbooks/chef_handler/attributes/default.rb +30 -0
  35. data/cookbooks/chef_handler/files/default/handlers/README +1 -0
  36. data/cookbooks/chef_handler/libraries/matchers.rb +29 -0
  37. data/cookbooks/chef_handler/metadata.json +29 -0
  38. data/cookbooks/chef_handler/metadata.rb +7 -0
  39. data/cookbooks/chef_handler/providers/default.rb +97 -0
  40. data/cookbooks/chef_handler/recipes/default.rb +33 -0
  41. data/cookbooks/chef_handler/recipes/json_file.rb +28 -0
  42. data/cookbooks/chef_handler/resources/default.rb +34 -0
  43. data/cookbooks/dmg/CHANGELOG.md +75 -0
  44. data/cookbooks/dmg/README.md +143 -0
  45. data/cookbooks/dmg/attributes/default.rb +20 -0
  46. data/cookbooks/dmg/metadata.json +30 -0
  47. data/cookbooks/dmg/metadata.rb +9 -0
  48. data/cookbooks/dmg/providers/package.rb +91 -0
  49. data/cookbooks/dmg/recipes/default.rb +18 -0
  50. data/cookbooks/dmg/resources/package.rb +37 -0
  51. data/cookbooks/vagrant/Berksfile +2 -0
  52. data/cookbooks/vagrant/CHANGELOG.md +7 -0
  53. data/cookbooks/vagrant/README.md +146 -0
  54. data/cookbooks/vagrant/TESTING.md +25 -0
  55. data/cookbooks/vagrant/attributes/default.rb +22 -0
  56. data/cookbooks/vagrant/metadata.rb +14 -0
  57. data/cookbooks/vagrant/providers/plugin.rb +50 -0
  58. data/cookbooks/vagrant/recipes/debian.rb +9 -0
  59. data/cookbooks/vagrant/recipes/default.rb +34 -0
  60. data/cookbooks/vagrant/recipes/fedora.rb +1 -0
  61. data/cookbooks/vagrant/recipes/mac_os_x.rb +7 -0
  62. data/cookbooks/vagrant/recipes/rhel.rb +9 -0
  63. data/cookbooks/vagrant/recipes/uninstall_gem.rb +7 -0
  64. data/cookbooks/vagrant/recipes/windows.rb +5 -0
  65. data/cookbooks/vagrant/resources/plugin.rb +8 -0
  66. data/cookbooks/virtualbox/README.md +167 -0
  67. data/cookbooks/virtualbox/attributes/default.rb +32 -0
  68. data/cookbooks/virtualbox/attributes/user.rb +22 -0
  69. data/cookbooks/virtualbox/attributes/webportal.rb +22 -0
  70. data/cookbooks/virtualbox/attributes/webservice.rb +24 -0
  71. data/cookbooks/virtualbox/files/ubuntu/machines_enabled +1 -0
  72. data/cookbooks/virtualbox/files/ubuntu/vboxcontrol +104 -0
  73. data/cookbooks/virtualbox/libraries/helpers.rb +30 -0
  74. data/cookbooks/virtualbox/metadata.rb +16 -0
  75. data/cookbooks/virtualbox/recipes/default.rb +70 -0
  76. data/cookbooks/virtualbox/recipes/systemservice.rb +56 -0
  77. data/cookbooks/virtualbox/recipes/user.rb +39 -0
  78. data/cookbooks/virtualbox/recipes/webportal.rb +58 -0
  79. data/cookbooks/virtualbox/recipes/webservice.rb +44 -0
  80. data/cookbooks/virtualbox/templates/ubuntu/config.erb +3 -0
  81. data/cookbooks/virtualbox/templates/ubuntu/config.php.erb +183 -0
  82. data/cookbooks/virtualbox/templates/ubuntu/vbox.cfg.erb +51 -0
  83. data/cookbooks/windows/CHANGELOG.md +268 -0
  84. data/cookbooks/windows/README.md +665 -0
  85. data/cookbooks/windows/attributes/default.rb +23 -0
  86. data/cookbooks/windows/files/default/handlers/windows_reboot_handler.rb +76 -0
  87. data/cookbooks/windows/libraries/feature_base.rb +59 -0
  88. data/cookbooks/windows/libraries/matchers.rb +450 -0
  89. data/cookbooks/windows/libraries/powershell_helper.rb +59 -0
  90. data/cookbooks/windows/libraries/powershell_out.rb +79 -0
  91. data/cookbooks/windows/libraries/registry_helper.rb +357 -0
  92. data/cookbooks/windows/libraries/version.rb +206 -0
  93. data/cookbooks/windows/libraries/windows_architecture_helper.rb +86 -0
  94. data/cookbooks/windows/libraries/windows_helper.rb +88 -0
  95. data/cookbooks/windows/libraries/windows_privileged.rb +94 -0
  96. data/cookbooks/windows/metadata.json +31 -0
  97. data/cookbooks/windows/metadata.rb +9 -0
  98. data/cookbooks/windows/providers/auto_run.rb +32 -0
  99. data/cookbooks/windows/providers/batch.rb +62 -0
  100. data/cookbooks/windows/providers/feature_dism.rb +64 -0
  101. data/cookbooks/windows/providers/feature_powershell.rb +38 -0
  102. data/cookbooks/windows/providers/feature_servermanagercmd.rb +47 -0
  103. data/cookbooks/windows/providers/package.rb +252 -0
  104. data/cookbooks/windows/providers/pagefile.rb +153 -0
  105. data/cookbooks/windows/providers/path.rb +35 -0
  106. data/cookbooks/windows/providers/printer.rb +100 -0
  107. data/cookbooks/windows/providers/printer_port.rb +102 -0
  108. data/cookbooks/windows/providers/reboot.rb +31 -0
  109. data/cookbooks/windows/providers/registry.rb +72 -0
  110. data/cookbooks/windows/providers/shortcut.rb +56 -0
  111. data/cookbooks/windows/providers/task.rb +128 -0
  112. data/cookbooks/windows/providers/zipfile.rb +91 -0
  113. data/cookbooks/windows/recipes/default.rb +34 -0
  114. data/cookbooks/windows/recipes/reboot_handler.rb +32 -0
  115. data/cookbooks/windows/resources/auto_run.rb +30 -0
  116. data/cookbooks/windows/resources/batch.rb +36 -0
  117. data/cookbooks/windows/resources/feature.rb +44 -0
  118. data/cookbooks/windows/resources/package.rb +46 -0
  119. data/cookbooks/windows/resources/pagefile.rb +29 -0
  120. data/cookbooks/windows/resources/path.rb +28 -0
  121. data/cookbooks/windows/resources/printer.rb +41 -0
  122. data/cookbooks/windows/resources/printer_port.rb +40 -0
  123. data/cookbooks/windows/resources/reboot.rb +29 -0
  124. data/cookbooks/windows/resources/registry.rb +34 -0
  125. data/cookbooks/windows/resources/shortcut.rb +35 -0
  126. data/cookbooks/windows/resources/task.rb +50 -0
  127. data/cookbooks/windows/resources/zipfile.rb +33 -0
  128. data/cookbooks/yum/CHANGELOG.md +212 -0
  129. data/cookbooks/yum/README.md +268 -0
  130. data/cookbooks/yum/attributes/main.rb +97 -0
  131. data/cookbooks/yum/libraries/matchers.rb +27 -0
  132. data/cookbooks/yum/metadata.json +34 -0
  133. data/cookbooks/yum/metadata.rb +13 -0
  134. data/cookbooks/yum/providers/globalconfig.rb +37 -0
  135. data/cookbooks/yum/providers/repository.rb +85 -0
  136. data/cookbooks/yum/recipes/default.rb +34 -0
  137. data/cookbooks/yum/resources/globalconfig.rb +105 -0
  138. data/cookbooks/yum/resources/repository.rb +63 -0
  139. data/cookbooks/yum/templates/default/main.erb +251 -0
  140. data/cookbooks/yum/templates/default/repo.erb +109 -0
  141. data/lib/madscience/version.rb +3 -0
  142. data/lib/madscience.rb +5 -0
  143. data/madscience.gemspec +44 -0
  144. data/new_gem_version.rb +6 -0
  145. data/node-data.json +3 -0
  146. data/site-cookbooks/madscience-vagrant-cookbook/CHANGELOG.md +13 -0
  147. data/site-cookbooks/madscience-vagrant-cookbook/README.md +53 -0
  148. data/site-cookbooks/madscience-vagrant-cookbook/metadata.rb +17 -0
  149. data/site-cookbooks/madscience-vagrant-cookbook/recipes/default.rb +87 -0
  150. data/solo.rb +6 -0
  151. metadata +337 -0
@@ -0,0 +1,86 @@
1
+ # Try to include from core chef, if error then monkey patch it in.
2
+
3
+ begin
4
+ include Chef::Mixin::WindowsArchitectureHelper
5
+ rescue
6
+ Chef::Log.debug("Chef::Mixin::WindowsArchitectureHelper not in core version, Monkey patching in.")
7
+
8
+ require 'chef/exceptions'
9
+ require 'win32/api' if Chef::Platform.windows?
10
+
11
+ class Chef
12
+ module Mixin
13
+ module WindowsArchitectureHelper
14
+
15
+ def node_windows_architecture(node)
16
+ node['kernel']['machine'].to_sym
17
+ end
18
+
19
+ def wow64_architecture_override_required?(node, desired_architecture)
20
+ is_i386_windows_process? &&
21
+ node_windows_architecture(node) == :x86_64 &&
22
+ desired_architecture == :x86_64
23
+ end
24
+
25
+ def node_supports_windows_architecture?(node, desired_architecture)
26
+ assert_valid_windows_architecture!(desired_architecture)
27
+ return (node_windows_architecture(node) == :x86_64 ||
28
+ desired_architecture == :i386) ? true : false
29
+ end
30
+
31
+ def valid_windows_architecture?(architecture)
32
+ return (architecture == :x86_64) || (architecture == :i386)
33
+ end
34
+
35
+ def assert_valid_windows_architecture!(architecture)
36
+ if ! valid_windows_architecture?(architecture)
37
+ raise Chef::Exceptions::Win32ArchitectureIncorrect,
38
+ "The specified architecture was not valid. It must be one of :i386 or :x86_64"
39
+ end
40
+ end
41
+
42
+ def is_i386_windows_process?
43
+ Chef::Platform.windows? && 'X86'.casecmp(ENV['PROCESSOR_ARCHITECTURE']) == 0
44
+ end
45
+
46
+ def disable_wow64_file_redirection(node)
47
+ original_redirection_state = ['0'].pack('P')
48
+
49
+ if ((node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?)
50
+ win32_wow_64_disable_wow_64_fs_redirection =
51
+ ::Win32::API.new('Wow64DisableWow64FsRedirection', 'P', 'L', 'kernel32')
52
+
53
+ succeeded = win32_wow_64_disable_wow_64_fs_redirection.call(original_redirection_state)
54
+
55
+ if succeeded == 0
56
+ raise Win32APIError "Failed to disable Wow64 file redirection"
57
+ end
58
+
59
+ end
60
+
61
+ original_redirection_state
62
+ end
63
+
64
+ def restore_wow64_file_redirection(node, original_redirection_state)
65
+ if ( (node_windows_architecture(node) == :x86_64) && ::Chef::Platform.windows?)
66
+ win32_wow_64_revert_wow_64_fs_redirection =
67
+ ::Win32::API.new('Wow64RevertWow64FsRedirection', 'P', 'L', 'kernel32')
68
+
69
+ succeeded = win32_wow_64_revert_wow_64_fs_redirection.call(original_redirection_state)
70
+
71
+ if succeeded == 0
72
+ raise Win32APIError "Failed to revert Wow64 file redirection"
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ # Making sure this library is available to Chef::Mixin::PowershellOut
82
+ # Required for clients that don't have Chef::Mixin::WindowsArchitectureHelper in
83
+ # core chef.
84
+ if ::Chef::Platform.windows?
85
+ Chef::Mixin::PowershellOut.send(:include, Chef::Mixin::WindowsArchitectureHelper)
86
+ end
@@ -0,0 +1,88 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Cookbook Name:: windows
4
+ # Library:: helper
5
+ #
6
+ # Copyright:: 2011, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require 'uri'
21
+
22
+ module Windows
23
+ module Helper
24
+
25
+ AUTO_RUN_KEY = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'.freeze unless defined?(AUTO_RUN_KEY)
26
+ ENV_KEY = 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment'.freeze unless defined?(ENV_KEY)
27
+
28
+ # returns windows friendly version of the provided path,
29
+ # ensures backslashes are used everywhere
30
+ def win_friendly_path(path)
31
+ path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR) if path
32
+ end
33
+
34
+ # account for Window's wacky File System Redirector
35
+ # http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx
36
+ # especially important for 32-bit processes (like Ruby) on a
37
+ # 64-bit instance of Windows.
38
+ def locate_sysnative_cmd(cmd)
39
+ if ::File.exists?("#{ENV['WINDIR']}\\sysnative\\#{cmd}")
40
+ "#{ENV['WINDIR']}\\sysnative\\#{cmd}"
41
+ elsif ::File.exists?("#{ENV['WINDIR']}\\system32\\#{cmd}")
42
+ "#{ENV['WINDIR']}\\system32\\#{cmd}"
43
+ else
44
+ cmd
45
+ end
46
+ end
47
+
48
+ # Create a feature provider dependent value object.
49
+ # mainly created becasue Windows Feature names are
50
+ # different based on whether dism.exe or servicemanagercmd.exe
51
+ # is used for installation
52
+ def value_for_feature_provider(provider_hash)
53
+ p = Chef::Platform.find_provider_for_node(node, :windows_feature)
54
+ key = p.to_s.downcase.split('::').last
55
+ provider_hash[key] || provider_hash[key.to_sym]
56
+ end
57
+
58
+ # singleton instance of the Windows Version checker
59
+ def win_version
60
+ @win_version ||= Windows::Version.new
61
+ end
62
+
63
+ # if a file is local it returns a windows friendly path version
64
+ # if a file is remote it caches it locally
65
+ def cached_file(source, checksum=nil, windows_path=true)
66
+ @installer_file_path ||= begin
67
+
68
+ if source =~ ::URI::ABS_URI && %w[ftp http https].include?(URI.parse(source).scheme)
69
+ uri = ::URI.parse(source)
70
+ cache_file_path = "#{Chef::Config[:file_cache_path]}/#{::File.basename(::URI.unescape(uri.path))}"
71
+ Chef::Log.debug("Caching a copy of file #{source} at #{cache_file_path}")
72
+ r = Chef::Resource::RemoteFile.new(cache_file_path, run_context)
73
+ r.source(source)
74
+ r.backup(false)
75
+ r.checksum(checksum) if checksum
76
+ r.run_action(:create)
77
+ else
78
+ cache_file_path = source
79
+ end
80
+
81
+ windows_path ? win_friendly_path(cache_file_path) : cache_file_path
82
+ end
83
+ end
84
+
85
+ end
86
+ end
87
+
88
+ Chef::Recipe.send(:include, Windows::Helper)
@@ -0,0 +1,94 @@
1
+ #
2
+ # Author:: Doug MacEachern <dougm@vmware.com>
3
+ # Author:: Paul Morton (<pmorton@biaprotect.com>)
4
+ # Cookbook Name:: windows
5
+ # Library:: windows_privileged
6
+ #
7
+ # Copyright:: 2010, VMware, Inc.
8
+ # Copyright:: 2011, Business Intelligence Associates, Inc
9
+ #
10
+ # Licensed under the Apache License, Version 2.0 (the "License");
11
+ # you may not use this file except in compliance with the License.
12
+ # You may obtain a copy of the License at
13
+ #
14
+ # http://www.apache.org/licenses/LICENSE-2.0
15
+ #
16
+ # Unless required by applicable law or agreed to in writing, software
17
+ # distributed under the License is distributed on an "AS IS" BASIS,
18
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ # See the License for the specific language governing permissions and
20
+ # limitations under the License.
21
+ #
22
+
23
+ if RUBY_PLATFORM =~ /mswin|mingw32|windows/
24
+ require 'windows/error'
25
+ require 'windows/registry'
26
+ require 'windows/process'
27
+ require 'windows/security'
28
+ end
29
+
30
+ #helpers for Windows API calls that require privilege adjustments
31
+ class Chef
32
+ class WindowsPrivileged
33
+ if RUBY_PLATFORM =~ /mswin|mingw32|windows/
34
+ include Windows::Error
35
+ include Windows::Registry
36
+ include Windows::Process
37
+ include Windows::Security
38
+ end
39
+ #File -> Load Hive... in regedit.exe
40
+ def reg_load_key(name, file)
41
+ run(SE_BACKUP_NAME, SE_RESTORE_NAME) do
42
+ rc = RegLoadKey(HKEY_USERS, name.to_s, file)
43
+ if rc == ERROR_SUCCESS
44
+ return true
45
+ elsif rc == ERROR_SHARING_VIOLATION
46
+ return false
47
+ else
48
+ raise get_last_error(rc)
49
+ end
50
+ end
51
+ end
52
+
53
+ #File -> Unload Hive... in regedit.exe
54
+ def reg_unload_key(name)
55
+ run(SE_BACKUP_NAME, SE_RESTORE_NAME) do
56
+ rc = RegUnLoadKey(HKEY_USERS, name.to_s)
57
+ if rc != ERROR_SUCCESS
58
+ raise get_last_error(rc)
59
+ end
60
+ end
61
+ end
62
+
63
+ def run(*privileges)
64
+ token = [0].pack('L')
65
+
66
+ unless OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, token)
67
+ raise get_last_error
68
+ end
69
+ token = token.unpack('L')[0]
70
+
71
+ privileges.each do |name|
72
+ unless adjust_privilege(token, name, SE_PRIVILEGE_ENABLED)
73
+ raise get_last_error
74
+ end
75
+ end
76
+
77
+ begin
78
+ yield
79
+ ensure #disable privs
80
+ privileges.each do |name|
81
+ adjust_privilege(token, name, 0)
82
+ end
83
+ end
84
+ end
85
+
86
+ def adjust_privilege(token, priv, attr=0)
87
+ luid = [0,0].pack('Ll')
88
+ if LookupPrivilegeValue(nil, priv, luid)
89
+ new_state = [1, luid.unpack('Ll'), attr].flatten.pack('LLlL')
90
+ AdjustTokenPrivileges(token, 0, new_state, new_state.size, 0, 0)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "windows",
3
+ "version": "1.33.1",
4
+ "description": "Provides a set of useful Windows-specific primitives.",
5
+ "long_description": "Windows Cookbook\n================\nProvides a set of Windows-specific primitives (Chef resources) meant to aid in the creation of cookbooks/recipes targeting the Windows platform.\n\n\nRequirements\n-------------\nVersion 1.3.0+ of this cookbook requires Chef 0.10.10+.\n\n\n### Platforms\n* Windows XP\n* Windows Vista\n* Windows Server 2003 R2\n* Windows 7\n* Windows Server 2008 (R1, R2)\n\nThe `windows_task` LWRP requires Windows Server 2008 due to its API usage.\n\n### Cookbooks\nThe following cookbooks provided by Opscode are required as noted:\n\n* chef_handler (`windows::reboot_handler` leverages the chef_handler LWRP)\n\nAttributes\n----------\n* `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.\n\n\nResource/Provider\n-----------------\n### windows_auto_run\n#### Actions\n- :create: Create an item to be run at login\n- :remove: Remove an item that was previously setup to run at login\n\n#### Attribute Parameters\n- :name: Name attribute. The name of the value to be stored in the registry\n- :program: The program to be run at login\n- :args: The arguments for the program\n\n#### Examples\nRun BGInfo at login\n\n```ruby\nwindows_auto_run 'BGINFO' do\n program 'C:/Sysinternals/bginfo.exe'\n args '\\'C:/Sysinternals/Config.bgi\\' /NOLICPROMPT /TIMER:0'\n not_if { Registry.value_exists?(AUTO_RUN_KEY, 'BGINFO') }\n action :create\nend\n```\n\n### windows_batch\n(Chef 11.6.0 includes a built-in [batch](http://docs.opscode.com/resource_batch.html) resource, so use that in preference to `windows_batch` if possible.)\n\nExecute a batch script using the cmd.exe interpreter (much like the script resources for bash, csh, powershell, perl, python and ruby). A temporary file is created and executed like other script resources, rather than run inline. By their nature, Script resources are not idempotent, as they are completely up to the user's imagination. Use the `not_if` or `only_if` meta parameters to guard the resource for idempotence.\n\n#### Actions\n- :run: run the batch file\n\n#### Attribute Parameters\n- command: name attribute. Name of the command to execute.\n- code: quoted string of code to execute.\n- creates: a file this command creates - if the file exists, the command will not be run.\n- cwd: current working directory to run the command from.\n- flags: command line flags to pass to the interpreter when invoking.\n- user: A user name or user ID that we should change to before running this command.\n- group: A group name or group ID that we should change to before running this command.\n\n#### Examples\n```ruby\nwindows_batch 'unzip_and_move_ruby' do\n code <<-EOH\n 7z.exe x #{Chef::Config[:file_cache_path]}/ruby-1.8.7-p352-i386-mingw32.7z -oC:\\\\source -r -y\n xcopy C:\\\\source\\\\ruby-1.8.7-p352-i386-mingw32 C:\\\\ruby /e /y\n EOH\nend\n```\n\n```ruby\nwindows_batch 'echo some env vars' do\n code <<-EOH\n echo %TEMP%\n echo %SYSTEMDRIVE%\n echo %PATH%\n echo %WINDIR%\n EOH\nend\n```\n\n### windows_feature\nWindows Roles and Features can be thought of as built-in operating system packages that ship with the OS. A server role is a set of software programs that, when they are installed and properly configured, lets a computer perform a specific function for multiple users or other computers within a network. A Role can have multiple Role Services that provide functionality to the Role. Role services are software programs that provide the functionality of a role. Features are software programs that, although they are not directly parts of roles, can support or augment the functionality of one or more roles, or improve the functionality of the server, regardless of which roles are installed. Collectively we refer to all of these attributes as 'features'.\n\nThis resource allows you to manage these 'features' in an unattended, idempotent way.\n\nThere are two providers for the `windows_features` which map into Microsoft's two major tools for managing roles/features: [Deployment Image Servicing and Management (DISM)](http://msdn.microsoft.com/en-us/library/dd371719%28v=vs.85%29.aspx) and [Servermanagercmd](http://technet.microsoft.com/en-us/library/ee344834%28WS.10%29.aspx) (The CLI for Server Manager). As Servermanagercmd is deprecated, Chef will set the default provider to `Chef::Provider::WindowsFeature::DISM` if DISM is present on the system being configured. The default provider will fall back to `Chef::Provider::WindowsFeature::ServerManagerCmd`.\n\nFor more information on Roles, Role Services and Features see the [Microsoft TechNet article on the topic](http://technet.microsoft.com/en-us/library/cc754923.aspx). For a complete list of all features that are available on a node type either of the following commands at a command prompt:\n\n```text\ndism /online /Get-Features\nservermanagercmd -query\n```\n\n#### Actions\n- :install: install a Windows role/feature\n- :remove: remove a Windows role/feature\n\n#### Attribute Parameters\n- feature_name: name of the feature/role to install. The same feature may have different names depending on the provider used (ie DHCPServer vs DHCP; DNS-Server-Full-Role vs DNS).\n- all: Boolean. Optional. Default: false. DISM provider only. Forces all dependencies to be installed.\n- source: String. Optional. DISM provider only. Uses local repository for feature install.\n\n#### Providers\n- **Chef::Provider::WindowsFeature::DISM**: Uses Deployment Image Servicing and Management (DISM) to manage roles/features.\n- **Chef::Provider::WindowsFeature::ServerManagerCmd**: Uses Server Manager to manage roles/features.\n\n#### Examples\nEnable the node as a DHCP Server\n\n```ruby\nwindows_feature 'DHCPServer' do\n action :install\nend\n```\n\nEnable TFTP\n\n```ruby\nwindows_feature 'TFTP' do\n action :install\nend\n```\n\nEnable .Net 3.5.1 on Server 2012 using repository files on DVD and\ninstall all dependencies\n\n```ruby\nwindows_feature \"NetFx3\" do\n action :install\n all true\n source \"d:\\sources\\sxs\"\nend\n```\n\nDisable Telnet client/server\n\n```ruby\n%w[TelnetServer TelnetClient].each do |feature|\n windows_feature feature do\n action :remove\n end\nend\n```\n\n### windows_package\nManage Windows application packages in an unattended, idempotent way.\n\nThe following application installers are currently supported:\n\n* MSI packages\n* InstallShield\n* Wise InstallMaster\n* Inno Setup\n* Nullsoft Scriptable Install System\n\nIf the proper installer type is not passed into the resource's installer_type attribute, the provider will do it's best to identify the type by introspecting the installation package. If the installation type cannot be properly identified the `:custom` value can be passed into the installer_type attribute along with the proper flags for silent/quiet installation (using the `options` attribute..see example below).\n\n__PLEASE NOTE__ - For proper idempotence the resource's `package_name` should be the same as the 'DisplayName' registry value in the uninstallation data that is created during package installation. The easiest way to definitively find the proper 'DisplayName' value is to install the package on a machine and search for the uninstall information under the following registry keys:\n\n* `HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall`\n* `HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall`\n* `HKEY_LOCAL_MACHINE\\Software\\Wow6464Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall`\n\nFor maximum flexibility the `source` attribute supports both remote and local installation packages.\n\n#### Actions\n- :install: install a package\n- :remove: remove a package. The remove action is completely hit or miss as many application uninstallers do not support a full silent/quiet mode.\n\n#### Attribute Parameters\n- package_name: name attribute. The 'DisplayName' of the application installation package.\n- source: The source of the windows installer. This can either be a URI or a local path.\n- installer_type: They type of windows installation package. valid values are: :msi, :inno, :nsis, :wise, :installshield, :custom. If this value is not provided, the provider will do it's best to identify the installer type through introspection of the file.\n- checksum: useful if source is remote, the SHA-256 checksum of the file--if the local file matches the checksum, Chef will not download it\n- options: Additional options to pass the underlying installation command\n- timeout: set a timeout for the package download (default 600 seconds)\n- version: The version number of this package, as indicated by the 'DisplayVersion' value in one of the 'Uninstall' registry keys. If the given version number does equal the 'DisplayVersion' in the registry, the package will be installed.\n- success_codes: set an array of possible successful installation\n return codes. Previously this was hardcoded, but certain MSIs may\n have a different return code, e.g. 3010 for reboot required. Must be\n an array, and defaults to `[0, 42, 127]`.\n\n#### Examples\n\nInstall PuTTY (InnoSetup installer)\n```ruby\nwindows_package 'PuTTY version 0.60' do\n source 'http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.60-installer.exe'\n installer_type :inno\n action :install\nend\n```\n\nInstall 7-Zip (MSI installer)\n```ruby\nwindows_package '7-Zip 9.20 (x64 edition)' do\n source 'http://downloads.sourceforge.net/sevenzip/7z920-x64.msi'\n action :install\nend\n```\n\nInstall Notepad++ (Y U No Emacs?) using a local installer\n```ruby\nwindows_package 'Notepad++' do\n source 'c:/installation_files/npp.5.9.2.Installer.exe'\n action :install\nend\n```\n\nInstall VLC for that Xvid (NSIS installer)\n```ruby\nwindows_package 'VLC media player 1.1.10' do\n source 'http://superb-sea2.dl.sourceforge.net/project/vlc/1.1.10/win32/vlc-1.1.10-win32.exe'\n action :install\nend\n```\n\nInstall Firefox as custom installer and manually set the silent install flags\n```ruby\nwindows_package 'Mozilla Firefox 5.0 (x86 en-US)' do\n source 'http://archive.mozilla.org/pub/mozilla.org/mozilla.org/firefox/releases/5.0/win32/en-US/Firefox%20Setup%205.0.exe'\n options '-ms'\n installer_type :custom\n action :install\nend\n```\n\nGoogle Chrome FTW (MSI installer)\n```ruby\nwindows_package 'Google Chrome' do\n source 'https://dl-ssl.google.com/tag/s/appguid%3D%7B8A69D345-D564-463C-AFF1-A69D9E530F96%7D%26iid%3D%7B806F36C0-CB54-4A84-A3F3-0CF8A86575E0%7D%26lang%3Den%26browser%3D3%26usagestats%3D0%26appname%3DGoogle%2520Chrome%26needsadmin%3Dfalse/edgedl/chrome/install/GoogleChromeStandaloneEnterprise.msi'\n action :install\nend\n```\n\nRemove Google Chrome\n```ruby\nwindows_package 'Google Chrome' do\n action :remove\nend\n```\n\nRemove 7-Zip\n```ruby\nwindows_package '7-Zip 9.20 (x64 edition)' do\n action :remove\nend\n```\n\n### windows_printer_port\n\nCreate and delete TCP/IPv4 printer ports.\n\n#### Actions\n- :create: Create a TCIP/IPv4 printer port. This is the default action.\n- :delete: Delete a TCIP/IPv4 printer port\n\n#### Attribute Parameters\n- :ipv4_address: Name attribute. Required. IPv4 address, e.g. '10.0.24.34'\n- :port_name: Port name. Optional. Defaults to 'IP_' + :ipv4_address\n- :port_number: Port number. Optional. Defaults to 9100.\n- :port_description: Port description. Optional.\n- :snmp_enabled: Boolean. Optional. Defaults to false.\n- :port_protocol: Port protocol, 1 (RAW), or 2 (LPR). Optional. Defaults to 1.\n\n#### Examples\n\nCreate a TCP/IP printer port named 'IP_10.4.64.37' with all defaults\n```ruby\nwindows_printer_port '10.4.64.37' do\nend\n```\n\nDelete a printer port\n```ruby\nwindows_printer_port '10.4.64.37' do\n action :delete\nend\n```\n\nDelete a port with a custom port_name\n```ruby\nwindows_printer_port '10.4.64.38' do\n port_name 'My awesome port'\n action :delete\nend\n```\n\nCreate a port with more options\n```ruby\nwindows_printer_port '10.4.64.39' do\n port_name 'My awesome port'\n snmp_enabled true\n port_protocol 2\nend\n```\n\n### windows_printer\n\nCreate Windows printer. Note that this doesn't currently install a printer\ndriver. You must already have the driver installed on the system.\n\nThe Windows Printer LWRP will automatically create a TCP/IP printer port for you using the `ipv4_address` property. If you want more granular control over the printer port, just create it using the `windows_printer_port` LWRP before creating the printer.\n\n#### Actions\n- :create: Create a new printer\n- :delete: Delete a new printer\n\n#### Attribute Parameters\n- :device_id: Name attribute. Required. Printer queue name, e.g. 'HP LJ 5200 in fifth floor copy room'\n- :comment: Optional string describing the printer queue.\n- :default: Boolean. Optional. Defaults to false. Note that Windows sets the first printer defined to the default printer regardless of this setting.\n- :driver_name: String. Required. Exact name of printer driver. Note that the printer driver must already be installed on the node.\n- :location: Printer location, e.g. 'Fifth floor copy room', or 'US/NYC/Floor42/Room4207'\n- :shared: Boolean. Defaults to false.\n- :share_name: Printer share name.\n- :ipv4_address: Printer IPv4 address, e.g. '10.4.64.23'. You don't have to be able to ping the IP addresss to set it. Required.\n\nAn error of \"Set-WmiInstance : Generic failure\" is most likely due to the printer driver name not matching or not being installed.\n\n#### Examples\n\nCreate a printer\n```ruby\nwindows_printer 'HP LaserJet 5th Floor' do\n driver_name 'HP LaserJet 4100 Series PCL6'\n ipv4_address '10.4.64.38'\nend\n```\n\nDelete a printer. Note: this doesn't delete the associated printer port. See `windows_printer_port` above for how to delete the port.\n```ruby\nwindows_printer 'HP LaserJet 5th Floor' do\n action :delete\nend\n```\n\n### windows_reboot\nSets required data in the node's run_state to notify `WindowsRebootHandler` a reboot is requested. If Chef run completes successfully a reboot will occur if the `WindowsRebootHandler` is properly registered as a report handler. As an action of `:request` will cause a node to reboot every Chef run, this resource is usually notified by other resources...ie restart node after a package is installed (see example below).\n\n#### Actions\n- :request: requests a reboot at completion of successful Cher run. requires `WindowsRebootHandler` to be registered as a report handler.\n- :cancel: remove reboot request from node.run_state. this will cancel *ALL* previously requested reboots as this is a binary state.\n\n#### Attribute Parameters\n- :timeout: Name attribute. timeout delay in seconds to wait before proceeding with the requested reboot. default is 60 seconds\n- :reason: comment on the reason for the reboot. default is 'Opscode Chef initiated reboot'\n\n#### Examples\nIf the package installs, schedule a reboot at end of chef run\n```ruby\nwindows_reboot 60 do\n reason 'cause chef said so'\n action :nothing\nend\n\nwindows_package 'some_package' do\n action :install\n notifies :request, 'windows_reboot[60]'\nend\n```\n\nCancel the previously requested reboot\n```ruby\nwindows_reboot 60 do\n action :cancel\nend\n```\n\n### windows_registry\n(Chef 11.6.0 includes a built-in [registry_key](http://docs.opscode.com/resource_registry_key.html) resource, so use that in preference to `windows_registry` if possible.)\n\nCreates and modifies Windows registry keys.\n\n*Change in v1.3.0: The Win32 classes use `::Win32` to avoid namespace conflict with `Chef::Win32` (introduced in Chef 0.10.10).*\n\n#### Actions\n- :create: create a new registry key with the provided values.\n- :modify: modify an existing registry key with the provided values.\n- :force_modify: modify an existing registry key with the provided values. ensures the value is actually set by checking multiple times. useful for fighting race conditions where two processes are trying to set the same registry key. This will be updated in the near future to use 'RegNotifyChangeKeyValue' which is exposed by the WinAPI and allows a process to register for notification on a registry key change.\n- :remove: removes a value from an existing registry key\n\n#### Attribute Parameters\n- key_name: name attribute. The registry key to create/modify.\n- values: hash of the values to set under the registry key. The individual hash items will become respective 'Value name' => 'Value data' items in the registry key.\n- type: Type of key to create, defaults to REG_SZ. Must be a symbol, see the overview below for valid values.\n\n#### Registry key types\n- :binary: REG_BINARY\n- :string: REG_SZ\n- :multi_string: REG_MULTI_SZ\n- :expand_string: REG_EXPAND_SZ\n- :dword: REG_DWORD\n- :dword_big_endian: REG_DWORD_BIG_ENDIAN\n- :qword: REG_QWORD\n\n#### Examples\n\nMake the local windows proxy match the one set for Chef\n```ruby\nproxy = URI.parse(Chef::Config[:http_proxy])\nwindows_registry 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings' do\n values 'ProxyEnable' => 1, 'ProxyServer' => \"#{proxy.host}:#{proxy.port}\", 'ProxyOverride' => '<local>'\nend\n```\n\nEnable Remote Desktop and poke the firewall hole\n```ruby\nwindows_registry 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server' do\n values 'FdenyTSConnections' => 0\nend\n```\n\nDelete an item from the registry\n```ruby\nwindows_registry 'HKCU\\Software\\Test' do\n #Key is the name of the value that you want to delete the value is always empty\n values 'ValueToDelete' => ''\n action :remove\nend\n```\n\nAdd a REG_MULTI_SZ value to the registry\n```ruby\nwindows_registry 'HKCU\\Software\\Test' do\n values 'MultiString' => ['line 1', 'line 2', 'line 3']\n type :multi_string\nend\n```\n\n#### Library Methods\n\n```ruby\nRegistry.value_exists?('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run','BGINFO')\nRegistry.key_exists?('HKLM\\SOFTWARE\\Microsoft')\nBgInfo = Registry.get_value('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run','BGINFO')\n```\n\n### windows_path\n#### Actions\n- :add: Add an item to the system path\n- :remove: Remove an item from the system path\n\n#### Attribute Parameters\n- :path: Name attribute. The name of the value to add to the system path\n\n#### Examples\n\nAdd Sysinternals to the system path\n```ruby\nwindows_path 'C:\\Sysinternals' do\n action :add\nend\n```\n\nRemove 7-Zip from the system path\n```ruby\nwindows_path 'C:\\7-Zip' do\n action :remove\nend\n```\n\n### windows_task\nCreates, deletes or runs a Windows scheduled task. Requires Windows\nServer 2008 due to API usage.\n\n#### Actions\n- :create: creates a task\n- :delete: deletes a task\n- :run: runs a task\n- :change: changes the un/pw or command of a task\n\n#### Attribute Parameters\n- name: name attribute, The task name.\n- command: The command the task will run.\n- cwd: The directory the task will be run from.\n- user: The user to run the task as. (requires password)\n- password: The user's password. (requires user)\n- run_level: Run with limited or highest privileges.\n- frequency: Frequency with which to run the task. (hourly, daily, ect.)\n- frequency_modifier: Multiple for frequency. (15 minutes, 2 days)\n- start_day: Specifies the first date on which the task runs. Optional string (MM/DD/YYYY)\n- start_time: Specifies the start time to run the task. Optional string (HH:mm)\n\n#### Examples\n\nRun Chef every 15 minutes\n```ruby\nwindows_task 'Chef client' do\n user 'Administrator'\n password '$ecR3t'\n cwd 'C:\\chef\\bin'\n command 'chef-client -L C:\\tmp\\'\n run_level :highest\n frequency :minute\n frequency_modifier 15\nend\n```\n\nUpdate Chef Client task with new password and log location\n```ruby\nwindows_task 'Chef client' do\n user 'Administrator'\n password 'N3wPassW0Rd'\n cwd 'C:\\chef\\bin'\n command 'chef-client -L C:\\chef\\logs\\'\n action :change\nend\n```\n\nDelete a taks named 'old task'\n```ruby\nwindows_task 'old task' do\n action :delete\nend\n```\n\n### windows_zipfile\nMost version of Windows do not ship with native cli utility for managing compressed files. This resource provides a pure-ruby implementation for managing zip files. Be sure to use the `not_if` or `only_if` meta parameters to guard the resource for idempotence or action will be taken on the zip file every Chef run.\n\n#### Actions\n- :unzip: unzip a compressed file\n\n#### Attribute Parameters\n- path: name attribute. The path where files will be unzipped to.\n- source: The source of the zip file. This can either be a URI or a local path.\n- overwrite: force an overwrite of the files if the already exists.\n- checksum: useful if source is remote, the SHA-256 checksum of the file--if the local file matches the checksum, Chef will not download it\n\n#### Examples\n\nUnzip a remote zip file locally\n```ruby\nwindows_zipfile 'c:/bin' do\n source 'http://download.sysinternals.com/Files/SysinternalsSuite.zip'\n action :unzip\n not_if {::File.exists?('c:/bin/PsExec.exe')}\nend\n```\n\nUnzip a local zipfile\n```ruby\nwindows_zipfile 'c:/the_codez' do\n source 'c:/foo/baz/the_codez.zip'\n action :unzip\nend\n```\n\n\nException/Report Handlers\n-------------------------\n### WindowsRebootHandler\nRequired 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.\n\n### Initialization Arguments\n- `allow_pending_reboots`: indicator on whether the handler should act on a the Window's 'pending reboot' state. default is true\n- `timeout`: timeout delay in seconds to wait before proceeding with the reboot. default is 60 seconds\n- `reason`: comment on the reason for the reboot. default is 'Opscode Chef initiated reboot'\n\n\nWindows ChefSpec Matchers\n-------------------------\nThe Windows cookbook includes custom [ChefSpec](https://github.com/sethvargo/chefspec) matchers you can use to test your own cookbooks that consume Windows cookbook LWRPs.\n\n###Example Matcher Usage\n```ruby\nexpect(chef_run).to install_windows_package('Node.js').with(\n source: 'http://nodejs.org/dist/v0.10.26/x64/node-v0.10.26-x64.msi')\n```\n\n###Windows Cookbook Matchers\n* install_windows_package\n* remove_windows_package\n* install_windows_feature\n* remove_windows_feature\n* delete_windows_feature\n* create_windows_task\n* delete_windows_task\n* run_windows_task\n* change_windows_task\n* add_windows_path\n* remove_windows_path\n* run_windows_batch\n* set_windows_pagefile\n* unzip_windows_zipfile_to\n* zip_windows_zipfile_to\n* create_windows_shortcut\n* create_windows_auto_run\n* remove_windows_auto_run\n* create_windows_printer\n* delete_windows_printer\n* create_windows_printer_port\n* delete_windows_printer_port\n* request_windows_reboot\n* cancel_windows_reboot\n* create_windows_shortcut\n\n\nUsage\n-----\n\nPlace an explicit dependency on this cookbook (using depends in the cookbook's metadata.rb) from any cookbook where you would like to use the Windows-specific resources/providers that ship with this cookbook.\n\n```ruby\ndepends 'windows'\n```\n\n### default\nConvenience recipe that installs supporting gems for many of the resources/providers that ship with this cookbook.\n\n*Change in v1.3.0: Uses chef_gem instead of gem_package to ensure gem installation in Chef 0.10.10.*\n\n### reboot_handler\nLeverages the `chef_handler` LWRP to register the `WindowsRebootHandler` report handler that ships as part of this cookbook. By default this handler is set to automatically act on pending reboots. If you would like to change this behavior override `node['windows']['allow_pending_reboots']` and set the value to false. For example:\n\n```ruby\nname 'base'\ndescription 'base role'\noverride_attributes(\n 'windows' => {\n 'allow_pending_reboots' => false\n }\n)\n```\n\nThis will still allow a reboot to be explicitly requested via the `windows_reboot` LWRP.\n\n\nLicense & Authors\n-----------------\n- Author:: Seth Chisamore (<schisamo@opscode.com>)\n- Author:: Doug MacEachern (<dougm@vmware.com>)\n- Author:: Paul Morton (<pmorton@biaprotect.com>)\n- Author:: Doug Ireton (<doug.ireton@nordstrom.com>)\n\n```text\nCopyright 2011-2013, Opscode, Inc.\nCopyright 2010, VMware, Inc.\nCopyright 2011, Business Intelligence Associates, Inc\nCopyright 2012, Nordstrom, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n",
6
+ "maintainer": "Chef Software, Inc.",
7
+ "maintainer_email": "cookbooks@getchef.com",
8
+ "license": "Apache 2.0",
9
+ "platforms": {
10
+ "windows": ">= 0.0.0"
11
+ },
12
+ "dependencies": {
13
+ "chef_handler": ">= 0.0.0"
14
+ },
15
+ "recommendations": {
16
+ },
17
+ "suggestions": {
18
+ },
19
+ "conflicting": {
20
+ },
21
+ "providing": {
22
+ },
23
+ "replacing": {
24
+ },
25
+ "attributes": {
26
+ },
27
+ "groupings": {
28
+ },
29
+ "recipes": {
30
+ }
31
+ }
@@ -0,0 +1,9 @@
1
+ name 'windows'
2
+ maintainer 'Chef Software, Inc.'
3
+ maintainer_email 'cookbooks@getchef.com'
4
+ license 'Apache 2.0'
5
+ description 'Provides a set of useful Windows-specific primitives.'
6
+ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7
+ version '1.33.1'
8
+ supports 'windows'
9
+ depends 'chef_handler'
@@ -0,0 +1,32 @@
1
+ #
2
+ # Author:: Paul Morotn (<pmorton@biaprotect.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: auto_run
5
+ #
6
+ # Copyright:: 2011, Business Intelligence Associates, Inc
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ action :create do
22
+ windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do
23
+ values new_resource.name => "\"#{new_resource.program}\" #{new_resource.args}"
24
+ end
25
+ end
26
+
27
+ action :remove do
28
+ windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' do
29
+ values new_resource.name => ''
30
+ action :remove
31
+ end
32
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Cookbook Name:: windws
4
+ # Provider:: batch
5
+ #
6
+ # Copyright:: 2011, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'tempfile'
22
+ require 'chef/resource/execute'
23
+
24
+ action :run do
25
+ begin
26
+ script_file.puts(@new_resource.code)
27
+ script_file.close
28
+ set_owner_and_group
29
+
30
+ # cwd hax...shell_out on windows needs to support proper 'cwd'
31
+ # follow CHEF-2357 for more
32
+ cwd = @new_resource.cwd ? "cd \"#{@new_resource.cwd}\" & " : ""
33
+
34
+ r = Chef::Resource::Execute.new(@new_resource.name, run_context)
35
+ r.user(@new_resource.user)
36
+ r.group(@new_resource.group)
37
+ r.command("#{cwd}call \"#{script_file.path}\" #{@new_resource.flags}")
38
+ r.creates(@new_resource.creates)
39
+ r.returns(@new_resource.returns)
40
+ r.run_action(:run)
41
+
42
+ @new_resource.updated_by_last_action(r.updated_by_last_action?)
43
+ ensure
44
+ unlink_script_file
45
+ end
46
+ end
47
+
48
+ private
49
+ def set_owner_and_group
50
+ # FileUtils itself implements a no-op if +user+ or +group+ are nil
51
+ # You can prove this by running FileUtils.chown(nil,nil,'/tmp/file')
52
+ # as an unprivileged user.
53
+ FileUtils.chown(@new_resource.user, @new_resource.group, script_file.path)
54
+ end
55
+
56
+ def script_file
57
+ @script_file ||= Tempfile.open(['chef-script', '.bat'])
58
+ end
59
+
60
+ def unlink_script_file
61
+ @script_file && @script_file.close!
62
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: feature_dism
5
+ #
6
+ # Copyright:: 2011, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ include Chef::Provider::WindowsFeature::Base
22
+ include Chef::Mixin::ShellOut
23
+ include Windows::Helper
24
+
25
+ def install_feature(name)
26
+ addsource = @new_resource.source ? "/LimitAccess /Source:\"#{@new_resource.source}\"" : ""
27
+ addall = @new_resource.all ? "/All" : ""
28
+ shell_out!("#{dism} /online /enable-feature /featurename:#{@new_resource.feature_name} /norestart #{addsource} #{addall}", {:returns => [0,42,127,3010]})
29
+ end
30
+
31
+ def remove_feature(name)
32
+ shell_out!("#{dism} /online /disable-feature /featurename:#{@new_resource.feature_name} /norestart", {:returns => [0,42,127,3010]})
33
+ end
34
+
35
+ def delete_feature(name)
36
+ if win_version.major_version >= 6 and win_version.minor_version >=2
37
+ shell_out!("#{dism} /online /disable-feature /featurename:#{@new_resource.feature_name} /Remove /norestart", {:returns => [0,42,127,3010]})
38
+ else
39
+ raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} :delete action not support on #{win_version.sku}"
40
+ end
41
+ end
42
+
43
+ def installed?
44
+ @installed ||= begin
45
+ cmd = shell_out("#{dism} /online /Get-Features", {:returns => [0,42,127]})
46
+ cmd.stderr.empty? && (cmd.stdout =~ /^Feature Name : #{@new_resource.feature_name}.?$\n^State : Enabled.?$/i)
47
+ end
48
+ end
49
+
50
+ def available?
51
+ @available ||= begin
52
+ cmd = shell_out("#{dism} /online /Get-Features", {:returns => [0,42,127]})
53
+ cmd.stderr.empty? && (cmd.stdout !~ /^Feature Name : #{@new_resource.feature_name}.?$\n^State : .* with payload removed.?$/i)
54
+ end
55
+ end
56
+
57
+ private
58
+ # account for File System Redirector
59
+ # http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx
60
+ def dism
61
+ @dism ||= begin
62
+ locate_sysnative_cmd("dism.exe")
63
+ end
64
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Author:: Greg Zapp (<greg.zapp@gmail.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: feature_powershell
5
+ #
6
+
7
+ include Chef::Provider::WindowsFeature::Base
8
+ include Chef::Mixin::PowershellOut
9
+ include Windows::Helper
10
+
11
+ def install_feature(name)
12
+ cmd = powershell_out("Install-WindowsFeature #{@new_resource.feature_name}")
13
+ Chef::Log.info(cmd.stdout)
14
+ end
15
+
16
+ def remove_feature(name)
17
+ cmd = powershell_out("Uninstall-WindowsFeature #{@new_resource.feature_name}")
18
+ Chef::Log.info(cmd.stdout)
19
+ end
20
+
21
+ def delete_feature(name)
22
+ cmd = powershell_out("Uninstall-WindowsFeature #{@new_resource.feature_name} -Remove")
23
+ Chef::Log.info(cmd.stdout)
24
+ end
25
+
26
+ def installed?
27
+ @installed ||= begin
28
+ cmd = powershell_out("Get-WindowsFeature #{@new_resource.feature_name} | Select Installed | % { Write-Host $_.Installed }")
29
+ cmd.stderr.empty? && cmd.stdout =~ /True/i
30
+ end
31
+ end
32
+
33
+ def available?
34
+ @available ||= begin
35
+ cmd = powershell_out("Get-WindowsFeature #{@new_resource.feature_name}")
36
+ cmd.stderr.empty? && cmd.stdout !~ /Removed/i
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Cookbook Name:: windows
4
+ # Provider:: feature_servermanagercmd
5
+ #
6
+ # Copyright:: 2011, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ include Chef::Provider::WindowsFeature::Base
22
+ include Chef::Mixin::ShellOut
23
+ include Windows::Helper
24
+
25
+ def install_feature(name)
26
+ shell_out!("#{servermanagercmd} -install #{@new_resource.feature_name}", {:returns => [0,42,127]})
27
+ end
28
+
29
+ def remove_feature(name)
30
+ shell_out!("#{servermanagercmd} -remove #{@new_resource.feature_name}", {:returns => [0,42,127]})
31
+ end
32
+
33
+ def installed?
34
+ @installed ||= begin
35
+ cmd = shell_out("#{servermanagercmd} -query", {:returns => [0,42,127]})
36
+ cmd.stderr.empty? && (cmd.stdout =~ /^\s*?\[X\]\s.+?\s\[#{@new_resource.feature_name}\]\s*$/i)
37
+ end
38
+ end
39
+
40
+ private
41
+ # account for File System Redirector
42
+ # http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx
43
+ def servermanagercmd
44
+ @servermanagercmd ||= begin
45
+ locate_sysnative_cmd("servermanagercmd.exe")
46
+ end
47
+ end