├── definitions ├── .gitignore ├── windows-2008r2-standard │ ├── oracle-cert.cer │ ├── install-chef.bat │ ├── install-vbox.bat │ ├── definition.rb │ ├── README.md │ └── Autounattend.xml ├── windows-7-enterprise │ ├── install-chef.bat │ ├── install-vbox.bat │ ├── oracle-cert.cer │ ├── definition.rb │ ├── README.md │ └── Autounattend.xml ├── .windows │ ├── oracle-cert.cer │ ├── install-chef.bat │ ├── install-vbox.bat │ └── session.rb └── .common │ └── session.rb ├── iso └── .gitignore ├── .gitignore ├── cookbooks ├── chef_handler │ ├── files │ │ └── default │ │ │ └── handlers │ │ │ └── README │ ├── metadata.rb │ ├── CHANGELOG.md │ ├── attributes │ │ └── default.rb │ ├── recipes │ │ ├── json_file.rb │ │ └── default.rb │ ├── resources │ │ └── default.rb │ ├── CONTRIBUTING │ ├── providers │ │ └── default.rb │ ├── README.md │ ├── metadata.json │ └── LICENSE ├── windows-fromscratch │ ├── files │ │ └── default │ │ │ └── config.bgi │ ├── README.md │ ├── attributes │ │ └── default.rb │ ├── metadata.rb │ ├── recipes │ │ ├── background.rb │ │ ├── default.rb │ │ ├── sysinternals.rb │ │ ├── domain_controller.rb │ │ ├── _annoyances.rb │ │ ├── bginfo.rb │ │ └── _ie_annoyances.rb │ └── CHANGELOG.md └── windows │ ├── metadata.rb │ ├── attributes │ └── default.rb │ ├── resources │ ├── path.rb │ ├── shortcut.rb │ ├── reboot.rb │ ├── auto_run.rb │ ├── zipfile.rb │ ├── registry.rb │ ├── feature.rb │ ├── batch.rb │ └── package.rb │ ├── providers │ ├── path.rb │ ├── reboot.rb │ ├── auto_run.rb │ ├── feature_servermanagercmd.rb │ ├── feature_dism.rb │ ├── batch.rb │ ├── shortcut.rb │ ├── registry.rb │ ├── zipfile.rb │ └── package.rb │ ├── recipes │ ├── default.rb │ └── reboot_handler.rb │ ├── CONTRIBUTING │ ├── libraries │ ├── feature_base.rb │ ├── windows_privileged.rb │ ├── helper.rb │ ├── registry_helper.rb │ └── version.rb │ ├── files │ └── default │ │ └── handlers │ │ └── windows_reboot_handler.rb │ ├── CHANGELOG.md │ ├── LICENSE │ ├── metadata.json │ └── README.md ├── Gemfile ├── Vagrantfile └── Gemfile.lock /definitions/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /iso/.gitignore: -------------------------------------------------------------------------------- 1 | *.iso 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | *.box 3 | virtualfloppy.vfd 4 | -------------------------------------------------------------------------------- /definitions/windows-2008r2-standard/oracle-cert.cer: -------------------------------------------------------------------------------- 1 | ../.windows/oracle-cert.cer -------------------------------------------------------------------------------- /definitions/windows-7-enterprise/install-chef.bat: -------------------------------------------------------------------------------- 1 | ../.windows/install-chef.bat -------------------------------------------------------------------------------- /definitions/windows-7-enterprise/install-vbox.bat: -------------------------------------------------------------------------------- 1 | ../.windows/install-vbox.bat -------------------------------------------------------------------------------- /definitions/windows-7-enterprise/oracle-cert.cer: -------------------------------------------------------------------------------- 1 | ../.windows/oracle-cert.cer -------------------------------------------------------------------------------- /definitions/windows-2008r2-standard/install-chef.bat: -------------------------------------------------------------------------------- 1 | ../.windows/install-chef.bat -------------------------------------------------------------------------------- /definitions/windows-2008r2-standard/install-vbox.bat: -------------------------------------------------------------------------------- 1 | ../.windows/install-vbox.bat -------------------------------------------------------------------------------- /cookbooks/chef_handler/files/default/handlers/README: -------------------------------------------------------------------------------- 1 | This directory contains Chef handlers to distribute to your nodes. 2 | -------------------------------------------------------------------------------- /definitions/.windows/oracle-cert.cer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hh/windows-fromscratch/HEAD/definitions/.windows/oracle-cert.cer -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/files/default/config.bgi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hh/windows-fromscratch/HEAD/cookbooks/windows-fromscratch/files/default/config.bgi -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/README.md: -------------------------------------------------------------------------------- 1 | Description 2 | =========== 3 | 4 | Requirements 5 | ============ 6 | 7 | Attributes 8 | ========== 9 | 10 | Usage 11 | ===== 12 | 13 | -------------------------------------------------------------------------------- /definitions/.windows/install-chef.bat: -------------------------------------------------------------------------------- 1 | cmd /C cscript %TEMP%\wget.vbs /url:http://www.opscode.com/chef/install.msi /path:%TEMP%\chef-client.msi 2 | cmd /C msiexec /qn /i %TEMP%\chef-client.msi 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source :rubygems 2 | gem 'veewee' #, :git => 'git://github.com/hh/veewee.git' 3 | gem "em-winrm" #:, :git => 'git://github.com/hh/em-winrm.git', :ref => '31745601d3' 4 | gem 'vagrant-windows' 5 | -------------------------------------------------------------------------------- /definitions/.windows/install-vbox.bat: -------------------------------------------------------------------------------- 1 | cmd /c certutil -addstore -f "TrustedPublisher" a:oracle-cert.cer 2 | cmd /c e:\VBoxWindowsAdditions-amd64.exe /S 3 | cmd /c shutdown.exe /r /t 0 /d p:2:4 /c "Vagrant reboot for VBoxWindowsAdditions" 4 | 5 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/metadata.rb: -------------------------------------------------------------------------------- 1 | maintainer "Opscode, Inc." 2 | maintainer_email "cookbooks@opscode.com" 3 | license "Apache 2.0" 4 | description "Distribute and enable Chef Exception and Report handlers" 5 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 6 | version "1.0.8" 7 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default['windows-fromscratch']['background'] = 'c:/Windows/Web/Wallpaper/Architecture/img0.jpg' 2 | default['sysinternals']['tools']['Process Monitor']='http://live.sysinternals.com/Procmon.exe' 3 | default['sysinternals']['tools']['BGInfo']='http://live.sysinternals.com/Bginfo.exe' 4 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/metadata.rb: -------------------------------------------------------------------------------- 1 | maintainer "YOUR_COMPANY_NAME" 2 | maintainer_email "YOUR_EMAIL" 3 | license "All rights reserved" 4 | description "Installs/Configures windows-fromscratch" 5 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 6 | version "0.1.0" 7 | depends 'windows' 8 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/recipes/background.rb: -------------------------------------------------------------------------------- 1 | require 'Win32API' 2 | 3 | ruby_block 'set windows background' do 4 | block do 5 | desktop = Win32API.new("user32", "SystemParametersInfo", ['L','L','P','L'] , 'L') 6 | desktop.Call(20,0,node['windows-fromscratch']['background'],1) 7 | end 8 | # not_if 'some code to check current desktop' 9 | end 10 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: windows-fromscratch 3 | # Recipe:: default 4 | # 5 | # Copyright 2012, YOUR_COMPANY_NAME 6 | # 7 | # All rights reserved - Do Not Redistribute 8 | # 9 | 10 | include_recipe '_ui_simplify' 11 | include_recipe 'background' 12 | include_recipe 'sysinternals' 13 | include_recipe 'bginfo' 14 | 15 | -------------------------------------------------------------------------------- /cookbooks/windows/metadata.rb: -------------------------------------------------------------------------------- 1 | maintainer "Opscode, Inc." 2 | maintainer_email "cookbooks@opscode.com" 3 | license "Apache 2.0" 4 | description "Provides a set of useful Windows-specific primitives." 5 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 6 | version "1.3.4" 7 | supports "windows" 8 | depends "chef_handler" 9 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## v1.0.8: 2 | 3 | * [COOK-1177] - doesn't work on windows due to use of unix specific attributes 4 | ## v1.0.6: 5 | 6 | * [COOK-1069] - typo in chef_handler readme 7 | 8 | ## v1.0.4: 9 | 10 | * [COOK-654] dont try and access a class before it has been loaded 11 | * fix bad boolean check (if vs unless) 12 | 13 | ## v1.0.2: 14 | 15 | * [COOK-620] ensure handler code is reloaded during daemonized chef runs 16 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG for windows-fromscratch 2 | 3 | This file is used to list changes made in each version of windows-fromscratch. 4 | 5 | ## 0.1.0: 6 | 7 | * Initial release of windows-fromscratch 8 | 9 | - - - 10 | Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown. 11 | 12 | The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown. 13 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/recipes/sysinternals.rb: -------------------------------------------------------------------------------- 1 | cache_dir=File.join( Chef::Config[:file_cache_path], 'sysinternals') 2 | directory cache_dir 3 | 4 | 5 | 6 | basepath = 'c:\opscode\chef\bin' 7 | 8 | node['sysinternals']['tools'].each do |toolname,url| 9 | exe=::File.join(basepath,::File.basename(url)) 10 | remote_file exe do 11 | source url 12 | not_if {::File.exists? exe} 13 | end 14 | #disable popup, we accept the eula! 15 | # http://peter.hahndorf.eu/blog/2010/03/07/WorkAroundSysinternalsLicensePopups.aspx 16 | windows_registry "HKCU\\Software\\Sysinternals\\#{toolname}" do 17 | values 'EulaAccepted' => 1 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /definitions/.common/session.rb: -------------------------------------------------------------------------------- 1 | COMMON_SESSION = { 2 | :boot_wait => "10", 3 | :cpu_count => "1", 4 | :disk_format => "VDI", 5 | :disk_size => "40960", 6 | :hostiocache => "off", 7 | :iso_download_timeout => "1000", 8 | :kickstart_port => "7122", 9 | :kickstart_timeout => "10000", 10 | :memory_size=> "384", 11 | :postinstall_timeout => "10000", 12 | :ssh_guest_port => "22", 13 | :ssh_host_port => "7222", 14 | :ssh_key => "", 15 | :ssh_login_timeout => "10000", 16 | :ssh_password => "vagrant", 17 | :ssh_user => "vagrant", 18 | :sudo_cmd => "echo '%p'|sudo -S sh '%f'", 19 | :virtualbox => { 20 | :vm_options => { 21 | :ioapic => "on", 22 | :pae => "on" 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /definitions/windows-2008r2-standard/definition.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | require File.dirname(__FILE__) + "/../.windows/session.rb" 3 | 4 | iso_src = "http://care.dlservice.microsoft.com//dl/download/7/5/E/75EC4E54-5B02-42D6-8879-D8D3A25FBEF7/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso" 5 | 6 | session = WINDOWS_SESSION.merge({ 7 | :os_type_id => 'Windows2008_64', 8 | :iso_download_instructions => "Download and install full featured software for 180-day trial at http://technet.microsoft.com/en-us/evalcenter/dd459137.aspx", 9 | :iso_src => iso_src, 10 | :iso_file => File.basename(iso_src), 11 | :iso_md5 => "4263be2cf3c59177c45085c0a7bc6ca5", 12 | :kickstart_port => "7190" 13 | }) 14 | 15 | Veewee::Session.declare session 16 | 17 | 18 | -------------------------------------------------------------------------------- /definitions/windows-7-enterprise/definition.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | require File.dirname(__FILE__) + "/../.windows/session.rb" 3 | 4 | iso_src = "http://wb.dlservice.microsoft.com/dl/download/release/Win7/3/b/a/3bac7d87-8ad2-4b7a-87b3-def36aee35fa/7600.16385.090713-1255_x64fre_enterprise_en-us_EVAL_Eval_Enterprise-GRMCENXEVAL_EN_DVD.iso" 5 | 6 | session = WINDOWS_SESSION.merge({ 7 | :os_type_id => 'Windows7_64', 8 | :iso_download_instructions => "Download Windows 7 Enterprise 90-day Trial at http://technet.microsoft.com/en-us/evalcenter/cc442495.aspx", 9 | :iso_file => File.basename(iso_src), 10 | :iso_src => iso_src, 11 | :iso_md5 => "1d0d239a252cb53e466d39e752b17c28", 12 | :kickstart_port => "7180" 13 | 14 | }) 15 | 16 | Veewee::Session.declare session 17 | -------------------------------------------------------------------------------- /cookbooks/windows/attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Attribute:: default 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 | default['windows']['allow_pending_reboots'] = true 22 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/recipes/domain_controller.rb: -------------------------------------------------------------------------------- 1 | windows_feature "NetFx3" 2 | windows_feature "DirectoryServices-DomainController" 3 | windows_feature "DirectoryServices-DomainController-Tools" 4 | 5 | file 'c:\dcunattended.txt' do 6 | content <<-EOC 7 | [DCINSTALL] 8 | InstallDNS=Yes 9 | DomainNetBiosName=vagrant 10 | NewDomainDNSName=vagrant.training 11 | SiteName=DefaultSite 12 | ReplicaOrNewDomain=domain 13 | NewDomain=forest 14 | ForestLevel=4 15 | DomainLevel=4 16 | SafeModeAdminPassword=Testing123! 17 | RebootOnSuccess=Yes 18 | EOC 19 | end 20 | 21 | # our ruby is 32bit, making file locations... interesting 22 | # http://en.wikipedia.org/wiki/WoW64#Registry_and_file_system 23 | dcpromo = 'c:\windows\sysnative\dcpromo.exe' 24 | # This command will reboot before it returns... chef-client ends here 25 | execute "#{dcpromo} /unattend:c:\\dcunattended.txt" 26 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/attributes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: chef_handlers 4 | # Attribute:: default 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 | default["chef_handler"]["handler_path"] = "#{File.expand_path(File.join(Chef::Config[:file_cache_path],'..'))}/handlers" -------------------------------------------------------------------------------- /definitions/.windows/session.rb: -------------------------------------------------------------------------------- 1 | require File.dirname(__FILE__) + "/../.common/session.rb" 2 | 3 | WINDOWS_SESSION = 4 | COMMON_SESSION.merge({ :boot_wait => "1", 5 | :boot_cmd_sequence => [''], 6 | :winrm_user => "vagrant", 7 | :winrm_password => "vagrant", 8 | :floppy_files => [ 9 | "Autounattend.xml", 10 | "oracle-cert.cer" 11 | ], 12 | :postinstall_files => [ 13 | "install-chef.bat", 14 | "install-vbox.bat" # would be interesting to only include this on vbox 15 | ], 16 | :video_memory_size => '48', 17 | :sudo_cmd => "%f", 18 | :shutdown_cmd => "shutdown /s /t 10 /f /d p:4:1 /c \"Vagrant Shutdown\"" }) 19 | 20 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/recipes/_annoyances.rb: -------------------------------------------------------------------------------- 1 | # http://technet.microsoft.com/en-us/library/cc732131.aspx 2 | # Look upnder Registry settings 3 | windows_registry 'HKLM\SOFTWARE\Microsoft\ServerManager\Oobe' do 4 | values 'DoNotOpenInitialConfigurationTasksAtLogon' => 1 5 | end 6 | windows_registry 'HKLM\SOFTWARE\Microsoft\ServerManager' do 7 | values 'DoNotOpenServerManagerAtLogon' => 1 8 | end 9 | 10 | # http://technet.microsoft.com/en-us/library/cc778526(v=ws.10).aspx#w2k3tr_set_tools_zgjt 11 | windows_registry 'HKLM\SOFTWARE\Policies\Microsoft\Windows NT\Reliability' do 12 | values 'ShutdownReasonUI' => 0, 'ShutdownReasonOn' => 0 13 | end 14 | 15 | # http://technet.microsoft.com/en-us/library/dd835564(v=ws.10).aspx#BKMK_AdminApprovalMode 16 | # http://technet.microsoft.com/en-us/library/dd835564(v=ws.10).aspx#BKMK_RegistryKeys 17 | windows_registry 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' do 18 | values 'EnableLUA' => 0 19 | end 20 | 21 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/path.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Paul Morotn () 3 | # Cookbook Name:: windows 4 | # Resource:: path 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 | def initialize(name,run_context=nil) 22 | super 23 | @action = :add 24 | end 25 | 26 | actions :add, :remove 27 | 28 | attribute :path, :kind_of => String, :name_attribute => true 29 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/shortcut.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern 3 | # Cookbook Name:: windows 4 | # Resource:: shortcut 5 | # 6 | # Copyright:: 2010, VMware, 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 | actions :create 22 | 23 | attribute :name, :kind_of => String 24 | attribute :target, :kind_of => String 25 | attribute :arguments, :kind_of => String 26 | attribute :description, :kind_of => String 27 | attribute :cwd, :kind_of => String 28 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/reboot.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Resource:: reboot 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 | actions :request, :cancel 22 | 23 | attribute :timeout, :kind_of => Integer, :default => 60, :name_attribute => true 24 | attribute :reason, :kind_of => String, :default => '' 25 | 26 | def initialize(name,run_context=nil) 27 | super 28 | @action = :request 29 | end 30 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/recipes/json_file.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: chef_handlers 4 | # Recipe:: json_file 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 | # force resource actions in compile phase so exception handler 22 | # fires for compile phase exceptions 23 | 24 | chef_handler "Chef::Handler::JsonFile" do 25 | source "chef/handler/json_file" 26 | arguments :path => '/var/chef/reports' 27 | action :nothing 28 | end.run_action(:enable) 29 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/auto_run.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Paul Morotn () 3 | # Cookbook Name:: windows 4 | # Resource:: 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 | def initialize(name,run_context=nil) 22 | super 23 | @action = :create 24 | end 25 | 26 | actions :create, :remove 27 | 28 | attribute :program, :kind_of => String 29 | attribute :name, :kind_of => String, :name_attribute => true 30 | attribute :args, :kind_of => String, :default => '' 31 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/path.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Paul Morotn () 3 | # Cookbook Name:: windows 4 | # Provider:: path 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 :add do 22 | env "PATH" do 23 | action :modify 24 | delim ::File::PATH_SEPARATOR 25 | value new_resource.path 26 | end 27 | end 28 | 29 | action :remove do 30 | env "PATH" do 31 | action :delete 32 | delim ::File::PATH_SEPARATOR 33 | value new_resource.path 34 | end 35 | end -------------------------------------------------------------------------------- /cookbooks/windows/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Recipe:: default 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 | # gems with precompiled binaries 22 | %w{ win32-api win32-service }.each do |win_gem| 23 | chef_gem win_gem do 24 | options '--platform=mswin32' 25 | action :install 26 | end 27 | end 28 | 29 | # the rest 30 | %w{ windows-api windows-pr win32-dir win32-event win32-mutex }.each do |win_gem| 31 | chef_gem win_gem do 32 | action :install 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/reboot.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Provider:: reboot 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 | action :request do 22 | node.run_state[:reboot_requested] = true 23 | node.run_state[:reboot_timeout] = @new_resource.timeout 24 | node.run_state[:reboot_reason] = @new_resource.reason 25 | end 26 | 27 | action :cancel do 28 | node.run_state.delete(:reboot_requested) 29 | node.run_state.delete(:reboot_timeout) 30 | node.run_state.delete(:reboot_reason) 31 | end 32 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/zipfile.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern () 3 | # Author:: Seth Chisamore () 4 | # Cookbook Name:: windows 5 | # Resource:: unzip 6 | # 7 | # Copyright:: 2010, VMware, Inc. 8 | # Copyright:: 2011, Opscode, 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 | actions :unzip, :zip 24 | 25 | attribute :path, :kind_of => String, :name_attribute => true 26 | attribute :source, :kind_of => String 27 | attribute :overwrite, :kind_of => [ TrueClass, FalseClass ], :default => false 28 | 29 | def initialize(name, run_context=nil) 30 | super 31 | @action = :unzip 32 | end 33 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/auto_run.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Paul Morotn () 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 -------------------------------------------------------------------------------- /cookbooks/windows/recipes/reboot_handler.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Recipe:: restart_handler 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 | remote_directory node['chef_handler']['handler_path'] do 22 | source 'handlers' 23 | recursive true 24 | action :create 25 | end 26 | 27 | chef_handler 'WindowsRebootHandler' do 28 | source "#{node['chef_handler']['handler_path']}/windows_reboot_handler.rb" 29 | arguments node['windows']['allow_pending_reboots'] 30 | supports :report => true, :exception => false 31 | action :enable 32 | end 33 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: chef_handlers 4 | # Recipe:: default 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 | Chef::Log.info("Chef Handlers will be at: #{node['chef_handler']['handler_path']}") 22 | 23 | remote_directory node['chef_handler']['handler_path'] do 24 | source 'handlers' 25 | # Just inherit permissions on Windows, don't try to set POSIX perms 26 | if node["platform"] != "windows" 27 | owner 'root' 28 | group 'root' 29 | mode "0755" 30 | recursive true 31 | end 32 | action :nothing 33 | end.run_action(:create) 34 | 35 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/registry.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern () 3 | # Author:: Seth Chisamore () 4 | # Cookbook Name:: windows 5 | # Resource:: registry 6 | # 7 | # Copyright:: 2010, VMware, Inc. 8 | # Copyright:: 2011, Opscode, 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 | actions :create, :modify, :force_modify, :remove 24 | 25 | attribute :key_name, :kind_of => String, :name_attribute => true 26 | attribute :values, :kind_of => Hash 27 | attribute :type, :kind_of => Symbol, :default => nil, :equal_to => [:binary] 28 | 29 | def initialize(name, run_context=nil) 30 | super 31 | @action = :modify 32 | @key_name = name 33 | end 34 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/resources/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: chef_handler 4 | # Resource:: default 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 | actions :enable, :disable 22 | 23 | attribute :class_name, :kind_of => String, :name_attribute => true 24 | attribute :source, :default => nil, :kind_of => String 25 | attribute :arguments, :default => [] 26 | attribute :supports, :kind_of => Hash, :default => {:report => true, :exception => true} 27 | 28 | # we have to set default for the supports attribute 29 | # in initializer since it is a 'reserved' attribute name 30 | def initialize(*args) 31 | super 32 | @action = :enable 33 | @supports = {:report => true, :exception => true} 34 | end 35 | -------------------------------------------------------------------------------- /cookbooks/windows/CONTRIBUTING: -------------------------------------------------------------------------------- 1 | If you would like to contribute, please open a ticket in JIRA: 2 | 3 | * http://tickets.opscode.com 4 | 5 | Create the ticket in the COOK project and use the cookbook name as the 6 | component. 7 | 8 | For all code contributions, we ask that contributors sign a 9 | contributor license agreement (CLA). Instructions may be found here: 10 | 11 | * http://wiki.opscode.com/display/chef/How+to+Contribute 12 | 13 | When contributing changes to individual cookbooks, please do not 14 | modify the version number in the metadata.rb. Also please do not 15 | update the CHANGELOG.md for a new version. Not all changes to a 16 | cookbook may be merged and released in the same versions. Opscode will 17 | handle the version updates during the release process. You are welcome 18 | to correct typos or otherwise make updates to documentation in the 19 | README. 20 | 21 | If a contribution adds new platforms or platform versions, indicate 22 | such in the body of the commit message(s), and update the relevant 23 | COOK ticket. When writing commit messages, it is helpful for others if 24 | you indicate the COOK ticket. For example: 25 | 26 | git commit -m '[COOK-1041] Updated pool resource to correctly delete.' 27 | 28 | In the ticket itself, it is also helpful if you include log output of 29 | a successful Chef run, but this is not absolutely required. 30 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/feature.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Resource:: feature 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 Windows::Helper 22 | 23 | actions :install, :remove 24 | 25 | attribute :feature_name, :kind_of => String, :name_attribute => true 26 | 27 | def initialize(name, run_context=nil) 28 | super 29 | @action = :install 30 | @provider = lookup_provider_constant(locate_default_provider) 31 | end 32 | 33 | private 34 | def locate_default_provider 35 | if ::File.exists?(locate_sysnative_cmd('dism.exe')) 36 | :windows_feature_dism 37 | elsif ::File.exists?(locate_sysnative_cmd('servermanagercmd.exe')) 38 | :windows_feature_servermanagercmd 39 | end 40 | end -------------------------------------------------------------------------------- /cookbooks/chef_handler/CONTRIBUTING: -------------------------------------------------------------------------------- 1 | If you would like to contribute, please open a ticket in JIRA: 2 | 3 | * http://tickets.opscode.com 4 | 5 | Create the ticket in the COOK project and use the cookbook name as the 6 | component. 7 | 8 | For all code contributions, we ask that contributors sign a 9 | contributor license agreement (CLA). Instructions may be found here: 10 | 11 | * http://wiki.opscode.com/display/chef/How+to+Contribute 12 | 13 | When contributing changes to individual cookbooks, please do not 14 | modify the version number in the metadata.rb. Also please do not 15 | update the CHANGELOG.md for a new version. Not all changes to a 16 | cookbook may be merged and released in the same versions. Opscode will 17 | handle the version updates during the release process. You are welcome 18 | to correct typos or otherwise make updates to documentation in the 19 | README. 20 | 21 | If a contribution adds new platforms or platform versions, indicate 22 | such in the body of the commit message(s), and update the relevant 23 | COOK ticket. When writing commit messages, it is helpful for others if 24 | you indicate the COOK ticket. For example: 25 | 26 | git commit -m '[COOK-1041] Updated pool resource to correctly delete.' 27 | 28 | In the ticket itself, it is also helpful if you include log output of 29 | a successful Chef run, but this is not absolutely required. 30 | -------------------------------------------------------------------------------- /cookbooks/windows/libraries/feature_base.rb: -------------------------------------------------------------------------------- 1 | class Chef 2 | class Provider 3 | class WindowsFeature 4 | module Base 5 | 6 | def action_install 7 | unless installed? 8 | install_feature(@new_resource.feature_name) 9 | @new_resource.updated_by_last_action(true) 10 | Chef::Log.info("#{@new_resource} installed feature") 11 | else 12 | Chef::Log.debug("#{@new_resource} is already installed - nothing to do") 13 | end 14 | end 15 | 16 | def action_remove 17 | if installed? 18 | remove_feature(@new_resource.feature_name) 19 | @new_resource.updated_by_last_action(true) 20 | Chef::Log.info("#{@new_resource} removed") 21 | else 22 | Chef::Log.debug("#{@new_resource} feature does not exist - nothing to do") 23 | end 24 | end 25 | 26 | def install_feature(name) 27 | raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :install" 28 | end 29 | 30 | def remove_feature(name) 31 | raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remove" 32 | end 33 | 34 | def installed? 35 | raise Chef::Exceptions::Override, "You must override installed? in #{self.to_s}" 36 | end 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/batch.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Resource:: 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 | actions :run 22 | 23 | attribute :command, :kind_of => String, :name_attribute => true 24 | attribute :cwd, :kind_of => String, :default => nil 25 | attribute :code, :kind_of => String, :default => nil 26 | attribute :user, :kind_of => [ String, Integer ], :default => nil 27 | attribute :group, :kind_of => [ String, Integer ], :default => nil 28 | attribute :creates, :kind_of => [ String ], :default => nil 29 | attribute :flags, :kind_of => [ String ], :default => nil 30 | attribute :returns, :kind_of => [Integer, Array], :default => 0 31 | 32 | def initialize(name, run_context=nil) 33 | super 34 | @action = :run 35 | @command = name 36 | end 37 | -------------------------------------------------------------------------------- /cookbooks/windows/resources/package.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Resource:: package 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 | actions :install, :remove 22 | 23 | attribute :package_name, :kind_of => String, :name_attribute => true 24 | attribute :source, :kind_of => String, :required => true 25 | attribute :version, :kind_of => String 26 | attribute :options, :kind_of => String 27 | attribute :installer_type, :kind_of => Symbol, :default => nil, :equal_to => [:msi, :inno, :nsis, :wise, :installshield, :custom] 28 | attribute :checksum, :kind_of => String 29 | attribute :timeout, :kind_of => Integer, :default => 600 30 | 31 | # TODO 32 | 33 | # add preseeding support 34 | #attribute :response_file 35 | 36 | # allow target dirtory of installation to be set 37 | #attribute :target_dir 38 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/feature_servermanagercmd.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 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}\]$/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 48 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/feature_dism.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 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 | shell_out!("#{dism} /online /enable-feature /featurename:#{@new_resource.feature_name} /norestart", {:returns => [0,42,127]}) 27 | end 28 | 29 | def remove_feature(name) 30 | shell_out!("#{dism} /online /disable-feature /featurename:#{@new_resource.feature_name} /norestart", {:returns => [0,42,127]}) 31 | end 32 | 33 | def installed? 34 | @installed ||= begin 35 | cmd = shell_out("#{dism} /online /Get-Features", {:returns => [0,42,127]}) 36 | cmd.stderr.empty? && (cmd.stdout =~ /^Feature Name : #{@new_resource.feature_name}.?$\n^State : Enabled.?$/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 dism 44 | @dism ||= begin 45 | locate_sysnative_cmd("dism.exe") 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /definitions/windows-7-enterprise/README.md: -------------------------------------------------------------------------------- 1 | You can download a free trial of Windows 7 Enterprise 90-day Trial 2 | 3 | url: http://technet.microsoft.com/en-us/evalcenter/cc442495.aspx 4 | file: 7600.16385.090713-1255_x64fre_enterprise_en-us_EVAL_Eval_Enterprise-GRMCENXEVAL_EN_DVD.iso 5 | md5sum: 1d0d239a252cb53e466d39e752b17c28 6 | 7 | ''' 8 | PS C:\Users\Administrator> Dism /Get-WIMInfo /WimFile:d:\sources\install.wim 9 | 10 | Deployment Image Servicing and Management tool 11 | Version: 6.1.7600.16385 12 | 13 | Details for image : d:\sources\install.wim 14 | 15 | Index : 1 16 | Name : Windows 7 ENTERPRISE 17 | Description : Windows 7 ENTERPRISE 18 | Size : 11,913,037,777 bytes 19 | 20 | The operation completed successfully. 21 | ''' 22 | 23 | - place it in a directory called iso 24 | 25 | The installation uses the Standard way for Windows Unattended installation. 26 | The XML file was created using the Windows AIK kit, but the file can also be edited by hand. 27 | 28 | To edit the Autounattend.xml and validate it: 29 | 30 | You can download The Windows® Automated Installation Kit (AIK) for Windows® 7: 31 | url: http://www.microsoft.com/download/en/details.aspx?id=5753 32 | file: KB3AIK_EN.iso 33 | md5sum: 1e73b24a89eceab9d50585b92db5482f 34 | 35 | - Building the machine creates a floppy that contains: 36 | - AutoUnattend.xml (that will configure the windows) 37 | - winrm-install.bat (activates the http and https listener + punches the firewall hole) 38 | 39 | AIK also includes dism, which will allow you to choose a specific version: 40 | 41 | If you want to install a different version, edit Autoattended.xml and replace the /IMAGE/NAME value with 42 | one of the names listed in the sources/install.wim on the install DVD .iso 43 | 44 | 45 | 46 | # Use the Name : from 'Dism.exe /Get-WIMInfo /WimFile:d:\sources\install.wim' 47 | # 48 | # 49 | # /IMAGE/NAME 50 | # Windows 7 ENTERPRISE 51 | # 52 | # 53 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/batch.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 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 63 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/recipes/bginfo.rb: -------------------------------------------------------------------------------- 1 | windows_auto_run 'BGINFO' do 2 | program 'c:\opscode\chef\bin\bginfo.exe' 3 | args "/NOLICPROMPT /TIMER:0" 4 | not_if { Registry.value_exists?(AUTO_RUN_KEY, 'BGINFO') } 5 | action :create 6 | end 7 | 8 | windows_registry 'HKEY_CURRENT_USER\Software\Winternals\BGInfo' do 9 | values 'RTF' => """{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}} 10 | {\\colortbl ;\\red255\\green255\\blue255;} 11 | \\viewkind4\\uc1\\pard\\fi-2880\\li2880\\tx2880\\cf1\\b\\fs24 Ohai from:\\tab\\protect #{node.name}\\protect0\\par 12 | Chef-Version:\\tab\\protect #{node.chef_packages['chef']['version']}\\protect0\\par 13 | Recipes:\\tab\\protect #{node.recipes}\\protect0\\par 14 | Boot Time:\\tab\\protect \\protect0\\par 15 | CPU:\\tab\\protect \\protect0\\par 16 | Default Gateway:\\tab\\protect \\protect0\\par 17 | DHCP Server:\\tab\\protect \\protect0\\par 18 | DNS Server:\\tab\\protect \\protect0\\par 19 | Free Space:\\tab\\protect \\protect0\\par 20 | Host Name:\\tab\\protect \\protect0\\par 21 | IE Version:\\tab\\protect \\protect0\\par 22 | IP Address:\\tab\\protect \\protect0\\par 23 | Logon Domain:\\tab\\protect \\protect0\\par 24 | Logon Server:\\tab\\protect \\protect0\\par 25 | MAC Address:\\tab\\protect \\protect0\\par 26 | Machine Domain:\\tab\\protect \\protect0\\par 27 | Memory:\\tab\\protect \\protect0\\par 28 | Network Card:\\tab\\protect \\protect0\\par 29 | Network Speed:\\tab\\protect \\protect0\\par 30 | Network Type:\\tab\\protect \\protect0\\par 31 | OS Version:\\tab\\protect \\protect0\\par 32 | Service Pack:\\tab\\protect \\protect0\\par 33 | Snapshot Time:\\tab\\protect \\protect0\\par 34 | Subnet Mask:\\tab\\protect \\protect0\\par 35 | System Type:\\tab\\protect \\protect0\\par 36 | User Name:\\tab\\protect \\protect0\\par 37 | Volumes:\\tab\\protect \\protect0\\par 38 | \\par 39 | } 40 | """ 41 | end 42 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/shortcut.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern 3 | # Cookbook Name:: windows 4 | # Provider:: shortcut 5 | # 6 | # Copyright:: 2010, VMware, 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 | def load_current_resource 22 | require 'win32ole' 23 | 24 | @link = WIN32OLE.new("WScript.Shell").CreateShortcut(@new_resource.name) 25 | 26 | @current_resource = Chef::Resource::WindowsShortcut.new(@new_resource.name) 27 | @current_resource.name(@new_resource.name) 28 | @current_resource.target(@link.TargetPath) 29 | @current_resource.arguments(@link.Arguments) 30 | @current_resource.description(@link.Description) 31 | @current_resource.cwd(@link.WorkingDirectory) 32 | end 33 | 34 | # Check to see if the shorcut needs any changes 35 | # 36 | # === Returns 37 | # :: If a change is required 38 | # :: If the shorcuts are identical 39 | def compare_shortcut 40 | [:target, :arguments, :description, :cwd].any? do |attr| 41 | !@new_resource.send(attr).nil? && @current_resource.send(attr) != @new_resource.send(attr) 42 | end 43 | end 44 | 45 | def action_create 46 | if compare_shortcut 47 | @link.TargetPath = @new_resource.target if @new_resource.target != nil 48 | @link.Arguments = @new_resource.arguments if @new_resource.arguments != nil 49 | @link.Description = @new_resource.description if @new_resource.description != nil 50 | @link.WorkingDirectory = @new_resource.cwd if @new_resource.cwd != nil 51 | #ignoring: WindowStyle, Hotkey, IconLocation 52 | @link.Save 53 | Chef::Log.info("Added #{@new_resource} shortcut") 54 | @updated = true 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/registry.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern () 3 | # Author:: Seth Chisamore () 4 | # Author:: Paul Morton () 5 | # Cookbook Name:: windows 6 | # Provider:: registry 7 | # 8 | # Copyright:: 2010, VMware, Inc. 9 | # Copyright:: 2011, Opscode, Inc. 10 | # Copyright:: 2011, Business Intelligence Associates, Inc 11 | # 12 | # Licensed under the Apache License, Version 2.0 (the "License"); 13 | # you may not use this file except in compliance with the License. 14 | # You may obtain a copy of the License at 15 | # 16 | # http://www.apache.org/licenses/LICENSE-2.0 17 | # 18 | # Unless required by applicable law or agreed to in writing, software 19 | # distributed under the License is distributed on an "AS IS" BASIS, 20 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | # See the License for the specific language governing permissions and 22 | # limitations under the License. 23 | # 24 | 25 | include Windows::RegistryHelper 26 | 27 | action :create do 28 | registry_update(:create) 29 | end 30 | 31 | action :modify do 32 | registry_update(:open) 33 | end 34 | 35 | action :force_modify do 36 | require 'timeout' 37 | Timeout.timeout(120) do 38 | @new_resource.values.each do |value_name, value_data| 39 | i = 1 40 | until i > 5 do 41 | desired_value_data = value_data 42 | current_value_data = get_value(@new_resource.key_name.dup, value_name.dup) 43 | if current_value_data.to_s == desired_value_data.to_s 44 | Chef::Log.debug("#{@new_resource} value [#{value_name}] desired [#{desired_value_data}] data already set. Check #{i}/5.") 45 | i+=1 46 | else 47 | Chef::Log.debug("#{@new_resource} value [#{value_name}] current [#{current_value_data}] data not equal to desired [#{desired_value_data}] data. Setting value and restarting check loop.") 48 | begin 49 | registry_update(:open) 50 | rescue Exception 51 | registry_update(:create) 52 | end 53 | i=0 # start count loop over 54 | end 55 | end 56 | end 57 | break 58 | end 59 | end 60 | 61 | action :remove do 62 | delete_value(@new_resource.key_name,@new_resource.values) 63 | end 64 | 65 | private 66 | def registry_update(mode) 67 | 68 | Chef::Log.debug("Registry Mode (#{mode})") 69 | updated = set_value(mode,@new_resource.key_name,@new_resource.values,@new_resource.type) 70 | @new_resource.updated_by_last_action(updated) 71 | 72 | end 73 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant::Config.run do |config| 2 | 3 | #The following timeout configuration is option, however if have 4 | #any large remote_file resources in your chef recipes, you may 5 | #experience timeouts (reported as 500 responses) 6 | config.winrm.timeout = 1800 #Set WinRM Timeout in seconds (Default 30) 7 | 8 | # Configure base box parameters 9 | config.vm.define :dc do |dc| 10 | dc.vm.host_name = "dc" 11 | dc.vm.box = "windows-2008r2-standard" 12 | dc.vm.box_url = "./windows-2008r2-standard.box" 13 | dc.vm.guest = :windows 14 | dc.vm.boot_mode = :gui 15 | dc.vm.forward_port 3389, 3390, :name => "rdp", :auto => true 16 | dc.vm.forward_port 5985, 5985, :name => "winrm", :auto => true 17 | dc.vm.customize ["modifyvm", :id, "--memory", 2048] 18 | dc.vm.customize ["modifyvm", :id, "--vram", 48] # I have a big screen 19 | dc.vm.customize ["modifyvm", :id, "--cpus", 4] # I have an 8 way 20 | dc.vm.network :hostonly, "1.1.1.2" 21 | dc.vm.provision :chef_solo do |chef| 22 | chef.cookbooks_path = "cookbooks" 23 | chef.json = {} 24 | chef.add_recipe("windows-fromscratch::_annoyances") 25 | chef.add_recipe("windows-fromscratch::sysinternals") 26 | chef.add_recipe("windows-fromscratch::bginfo") 27 | chef.add_recipe("windows-fromscratch::_ie_annoyances") 28 | # domain_controller forces a reboot! 29 | chef.add_recipe("windows-fromscratch::domain_controller") 30 | chef.add_recipe("windows-fromscratch::setup_winrm") 31 | end 32 | end 33 | 34 | # Configure base box parameters 35 | config.vm.define :member do |member| 36 | member.vm.host_name = "member" 37 | member.vm.box = "windows-2008r2-standard" 38 | member.vm.box_url = "./windows-2008r2-standard.box" 39 | member.vm.guest = :windows 40 | member.vm.boot_mode = :gui 41 | member.vm.forward_port 3389, 3390, :name => "rdp", :auto => true 42 | member.vm.forward_port 5985, 5985, :name => "winrm", :auto => true 43 | member.vm.customize ["modifyvm", :id, "--memory", 2048] 44 | member.vm.customize ["modifyvm", :id, "--vram", 48] # I have a big screen 45 | member.vm.customize ["modifyvm", :id, "--cpus", 4] # I have an 8 way 46 | member.vm.network :hostonly, "1.1.1.3" 47 | member.vm.provision :chef_solo do |chef| 48 | chef.cookbooks_path = "cookbooks" 49 | chef.json = {} 50 | chef.add_recipe("windows-fromscratch::_annoyances") 51 | chef.add_recipe("windows-fromscratch::sysinternals") 52 | chef.add_recipe("windows-fromscratch::bginfo") 53 | chef.add_recipe("windows-fromscratch::_ie_annoyances") 54 | chef.add_recipe("windows-fromscratch::setup_winrm") 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/providers/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore 3 | # Cookbook Name:: chef_handler 4 | # Provider:: default 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 | action :enable do 22 | # use load instead of require to ensure the handler file 23 | # is reloaded into memory each chef run. fixes COOK-620 24 | begin 25 | Object.send(:remove_const, klass) 26 | GC.start 27 | rescue 28 | Chef::Log.debug("#{@new_resource.class_name} has not been loaded.") 29 | end 30 | file_name = @new_resource.source 31 | file_name << ".rb" unless file_name =~ /.*\.rb$/ 32 | load file_name 33 | handler = klass.send(:new, *collect_args(@new_resource.arguments)) 34 | @new_resource.supports.each do |type, enable| 35 | if enable 36 | # we have to re-enable the handler every chef run 37 | # to ensure daemonized Chef always has the latest 38 | # handler code. TODO: add a :reload action 39 | Chef::Log.info("Enabling #{@new_resource} as a #{type} handler") 40 | Chef::Config.send("#{type.to_s}_handlers").delete_if {|v| v.class.to_s.include? @new_resource.class_name} 41 | Chef::Config.send("#{type.to_s}_handlers") << handler 42 | new_resource.updated_by_last_action(true) 43 | end 44 | end 45 | end 46 | 47 | action :disable do 48 | @new_resource.supports.each_key do |type| 49 | if enabled?(type) 50 | Chef::Log.info("Disabling #{@new_resource} as a #{type} handler") 51 | Chef::Config.send("#{type.to_s}_handlers").delete_if {|v| v.class.to_s.include? @new_resource.class_name} 52 | new_resource.updated_by_last_action(true) 53 | end 54 | end 55 | end 56 | 57 | def load_current_resource 58 | @current_resource = Chef::Resource::ChefHandler.new(@new_resource.name) 59 | @current_resource.class_name(@new_resource.class_name) 60 | @current_resource.source(@new_resource.source) 61 | @current_resource 62 | end 63 | 64 | private 65 | def enabled?(type) 66 | Chef::Config.send("#{type.to_s}_handlers").select do |handler| 67 | handler.class.to_s.include? @new_resource.class_name 68 | end.size >= 1 69 | end 70 | 71 | def collect_args(resource_args = []) 72 | if resource_args.is_a? Array 73 | resource_args 74 | else 75 | [resource_args] 76 | end 77 | end 78 | 79 | def klass 80 | @klass ||= begin 81 | @new_resource.class_name.split('::').inject(Kernel) {|scope, const_name| scope.const_get(const_name)} 82 | end 83 | end -------------------------------------------------------------------------------- /cookbooks/windows/libraries/windows_privileged.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern 3 | # Author:: Paul Morton () 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}", 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}") 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 -------------------------------------------------------------------------------- /definitions/windows-2008r2-standard/README.md: -------------------------------------------------------------------------------- 1 | You can download a free trial of Windows Server 2008 R2 with Service Pack 1 from two different locations manually: 2 | 3 | * url: http://technet.microsoft.com/en-us/evalcenter/dd459137.aspx 4 | * url: http://msdn.microsoft.com/en-us/evalcenter/ee175713.aspx 5 | 6 | But they seem to always generate the same url of http://care.dlservice.microsoft.com//dl/download/7/5/E/75EC4E54-5B02-42D6-8879-D8D3A25FBEF7/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso 7 | 8 | * 64bit 9 | * filename: 7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso 10 | * md5sum: 4263be2cf3c59177c45085c0a7bc6ca5 11 | 12 | 13 | The installation uses the Standard Windows Unattended installation. The XML file was created using the Windows AIK kit, but the file can also be edited by hand. 14 | 15 | To edit the Autounattend.xml and validate it you can download The Windows® Automated Installation Kit (AIK) for Windows® 7: 16 | 17 | * url: http://www.microsoft.com/download/en/details.aspx?id=5753 18 | * file: KB3AIK_EN.iso 19 | * md5sum: 1e73b24a89eceab9d50585b92db5482f 20 | 21 | AIK also includes dism, which will allow you to choose a specific version: 22 | 23 | If you want to install a different version, edit Autoattended.xml and replace the /IMAGE/NAME value with 24 | one of the names listed in the 2008r2 install.wim on the install DVD .iso 25 | 26 | 27 | ```xml 28 | 29 | 30 | /IMAGE/NAME 31 | Windows Server 2008 R2 SERVERSTANDARD 32 | 33 | 34 | ``` 35 | 36 | 37 | ``` 38 | PS C:\Users\Administrator> Dism /Get-WIMInfo /WimFile:d:\sources\install.wim 39 | 40 | Deployment Image Servicing and Management tool 41 | Version: 6.1.7600.16385 42 | 43 | Details for image : d:\sources\install.wim 44 | 45 | Index : 1 46 | Name : Windows Server 2008 R2 SERVERSTANDARD 47 | Description : Windows Server 2008 R2 SERVERSTANDARD 48 | Size : 10,510,643,622 bytes 49 | 50 | Index : 2 51 | Name : Windows Server 2008 R2 SERVERSTANDARDCORE 52 | Description : Windows Server 2008 R2 SERVERSTANDARDCORE 53 | Size : 3,564,132,307 bytes 54 | 55 | Index : 3 56 | Name : Windows Server 2008 R2 SERVERENTERPRISE 57 | Description : Windows Server 2008 R2 SERVERENTERPRISE 58 | Size : 10,511,024,733 bytes 59 | 60 | Index : 4 61 | Name : Windows Server 2008 R2 SERVERENTERPRISECORE 62 | Description : Windows Server 2008 R2 SERVERENTERPRISECORE 63 | Size : 3,564,106,331 bytes 64 | 65 | Index : 5 66 | Name : Windows Server 2008 R2 SERVERDATACENTER 67 | Description : Windows Server 2008 R2 SERVERDATACENTER 68 | Size : 10,511,131,897 bytes 69 | 70 | Index : 6 71 | Name : Windows Server 2008 R2 SERVERDATACENTERCORE 72 | Description : Windows Server 2008 R2 SERVERDATACENTERCORE 73 | Size : 3,564,144,547 bytes 74 | 75 | Index : 7 76 | Name : Windows Server 2008 R2 SERVERWEB 77 | Description : Windows Server 2008 R2 SERVERWEB 78 | Size : 10,520,222,743 bytes 79 | 80 | Index : 8 81 | Name : Windows Server 2008 R2 SERVERWEBCORE 82 | Description : Windows Server 2008 R2 SERVERWEBCORE 83 | Size : 3,562,750,400 bytes 84 | 85 | The operation completed successfully. 86 | ``` 87 | 88 | -------------------------------------------------------------------------------- /cookbooks/windows/files/default/handlers/windows_reboot_handler.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 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 | class WindowsRebootHandler < Chef::Handler 20 | include Chef::Mixin::ShellOut 21 | 22 | def initialize(allow_pending_reboots = true, timeout = 60, reason = "Opscode Chef initiated reboot") 23 | @allow_pending_reboots = allow_pending_reboots 24 | @timeout = timeout 25 | @reason = reason 26 | end 27 | 28 | def report 29 | log_message, reboot = begin 30 | if reboot_requested? 31 | ["chef_handler[#{self.class}] requested reboot will occur in #{timeout} seconds", true] 32 | elsif reboot_pending? 33 | if @allow_pending_reboots 34 | ["chef_handler[#{self.class}] reboot pending - automatic reboot will occur in #{timeout} seconds", true] 35 | else 36 | ["chef_handler[#{self.class}] reboot pending but handler not configured to act on pending reboots - please reboot node manually", false] 37 | end 38 | else 39 | ["chef_handler[#{self.class}] no reboot requested or pending", false] 40 | end 41 | end 42 | 43 | Chef::Log.warn(log_message) 44 | shell_out!("shutdown /r /t #{timeout} /c \"#{reason}\"") if reboot 45 | end 46 | 47 | private 48 | # reboot cause CHEF says so: 49 | # reboot explicitly requested in our cookbook code 50 | def reboot_requested? 51 | node.run_state[:reboot_requested] == true 52 | end 53 | 54 | # reboot cause WIN says so: 55 | # reboot pending because of some configuration action we performed 56 | def reboot_pending? 57 | # Any files listed here means reboot needed 58 | (Registry.key_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations') && 59 | Registry.get_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager','PendingFileRenameOperations').any?) || 60 | # 1 for any value means reboot pending 61 | # "9306cdfc-c4a1-4a22-9996-848cb67eddc3"=1 62 | (Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') && 63 | Registry.get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired').select{|v| v[2] == 1 }.any?) || 64 | # 1 or 2 for 'Flags' value means reboot pending 65 | (Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') && 66 | [1,2].include?(Registry::get_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile','Flags'))) 67 | end 68 | 69 | def timeout 70 | node.run_state[:reboot_timeout] || @timeout 71 | end 72 | 73 | def reason 74 | node.run_state[:reboot_reason] || @reason 75 | end 76 | end -------------------------------------------------------------------------------- /cookbooks/windows/libraries/helper.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 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 | 21 | module Windows 22 | module Helper 23 | 24 | AUTO_RUN_KEY = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 25 | ENV_KEY = 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' 26 | 27 | # returns windows friendly version of the provided path, 28 | # ensures backslashes are used everywhere 29 | def win_friendly_path(path) 30 | path.gsub(::File::SEPARATOR, ::File::ALT_SEPARATOR) if path 31 | end 32 | 33 | # account for Window's wacky File System Redirector 34 | # http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx 35 | # especially important for 32-bit processes (like Ruby) on a 36 | # 64-bit instance of Windows. 37 | def locate_sysnative_cmd(cmd) 38 | if ::File.exists?("#{ENV['WINDIR']}\\sysnative\\#{cmd}") 39 | "#{ENV['WINDIR']}\\sysnative\\#{cmd}" 40 | elsif ::File.exists?("#{ENV['WINDIR']}\\system32\\#{cmd}") 41 | "#{ENV['WINDIR']}\\system32\\#{cmd}" 42 | else 43 | cmd 44 | end 45 | end 46 | 47 | # Create a feature provider dependent value object. 48 | # mainly created becasue Windows Feature names are 49 | # different based on whether dism.exe or servicemanagercmd.exe 50 | # is used for installation 51 | def value_for_feature_provider(provider_hash) 52 | p = Chef::Platform.find_provider_for_node(node, :windows_feature) 53 | key = p.to_s.downcase.split('::').last 54 | provider_hash[key] || provider_hash[key.to_sym] 55 | end 56 | 57 | # singleton instance of the Windows Version checker 58 | def win_version 59 | @win_version ||= Windows::Version.new 60 | end 61 | 62 | # if a file is local it returns a windows friendly path version 63 | # if a file is remote it caches it locally 64 | def cached_file(source, checksum=nil, windows_path=true) 65 | @installer_file_path ||= begin 66 | 67 | if(source =~ /^(https?:\/\/)(.*\/)(.*)$/) 68 | cache_file_path = "#{Chef::Config[:file_cache_path]}/#{::File.basename(source)}" 69 | Chef::Log.debug("Caching a copy of file #{source} at #{cache_file_path}") 70 | r = Chef::Resource::RemoteFile.new(cache_file_path, run_context) 71 | r.source(source) 72 | r.backup(false) 73 | r.checksum(checksum) if checksum 74 | r.run_action(:create) 75 | else 76 | cache_file_path = source 77 | end 78 | 79 | windows_path ? win_friendly_path(cache_file_path) : cache_file_path 80 | end 81 | end 82 | 83 | end 84 | end 85 | 86 | Chef::Recipe.send(:include, Windows::Helper) 87 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/zipfile.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern () 3 | # Author:: Seth Chisamore () 4 | # Cookbook Name:: windows 5 | # Provider:: unzip 6 | # 7 | # Copyright:: 2010, VMware, Inc. 8 | # Copyright:: 2011, Opscode, 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 | include Windows::Helper 24 | 25 | require 'find' 26 | 27 | action :unzip do 28 | ensure_rubyzip_gem_installed 29 | Chef::Log.debug("unzip #{@new_resource.source} => #{@new_resource.path} (overwrite=#{@new_resource.overwrite})") 30 | 31 | Zip::ZipFile.open(cached_file(@new_resource.source)) do |zip| 32 | zip.each do |entry| 33 | path = ::File.join(@new_resource.path, entry.name) 34 | FileUtils.mkdir_p(::File.dirname(path)) 35 | if @new_resource.overwrite && ::File.exists?(path) && !::File.directory?(path) 36 | FileUtils.rm(path) 37 | end 38 | zip.extract(entry, path) 39 | end 40 | end 41 | @new_resource.updated_by_last_action(true) 42 | end 43 | 44 | action :zip do 45 | ensure_rubyzip_gem_installed 46 | # sanitize paths for windows. 47 | @new_resource.source.downcase.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR) 48 | @new_resource.path.downcase.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR) 49 | Chef::Log.debug("zip #{@new_resource.source} => #{@new_resource.path} (overwrite=#{@new_resource.overwrite})") 50 | 51 | if @new_resource.overwrite == false && ::File.exists?(@new_resource.path) 52 | Chef::Log.info("file #{@new_resource.path} already exists and overwrite is set to false, exiting") 53 | else 54 | # delete the archive if it already exists, because we are recreating it. 55 | if ::File.exists?(@new_resource.path) 56 | ::File.unlink(@new_resource.path) 57 | end 58 | # only supporting compression of a single directory (recursively). 59 | if ::File.directory?(@new_resource.source) 60 | z = Zip::ZipFile.new(@new_resource.path, true) 61 | unless @new_resource.source =~ /::File::ALT_SEPARATOR$/ 62 | @new_resource.source << ::File::ALT_SEPARATOR 63 | end 64 | Find.find(@new_resource.source) do |f| 65 | f.downcase.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR) 66 | # don't add root directory to the zipfile. 67 | next if f == @new_resource.source 68 | # strip the root directory from the filename before adding it to the zipfile. 69 | zip_fname = f.sub(@new_resource.source, '') 70 | Chef::Log.debug("adding #{zip_fname} to archive, sourcefile is: #{f}") 71 | z.add(zip_fname, f) 72 | end 73 | z.close 74 | else 75 | Chef::Log.info("Single directory must be specified for compression, and #{@new_resource.source} does not meet that criteria.") 76 | end 77 | end 78 | end 79 | 80 | private 81 | def ensure_rubyzip_gem_installed 82 | begin 83 | require 'zip/zip' 84 | rescue LoadError 85 | Chef::Log.info("Missing gem 'rubyzip'...installing now.") 86 | chef_gem "rubyzip" do 87 | version "0.9.5" 88 | end 89 | require 'zip/zip' 90 | end 91 | end 92 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: http://rubygems.org/ 3 | specs: 4 | CFPropertyList (2.0.17) 5 | libxml-ruby (>= 1.1.0) 6 | rake (>= 0.7.0) 7 | Platform (0.4.0) 8 | akami (1.2.0) 9 | gyoku (>= 0.4.0) 10 | nokogiri (>= 1.4.0) 11 | ansi (1.3.0) 12 | archive-tar-minitar (0.5.2) 13 | builder (3.1.4) 14 | childprocess (0.3.6) 15 | ffi (~> 1.0, >= 1.0.6) 16 | cucumber (1.2.1) 17 | builder (>= 2.1.2) 18 | diff-lcs (>= 1.1.3) 19 | gherkin (~> 2.11.0) 20 | json (>= 1.4.6) 21 | diff-lcs (1.1.3) 22 | em-winrm (0.5.4) 23 | eventmachine (= 1.0.0.beta.3) 24 | mixlib-log (>= 1.3.0) 25 | uuidtools (~> 2.1.1) 26 | winrm (~> 1.1.0) 27 | erubis (2.7.0) 28 | eventmachine (1.0.0.beta.3) 29 | excon (0.16.10) 30 | ffi (1.3.1) 31 | fission (0.4.0) 32 | CFPropertyList (~> 2.0.17) 33 | fog (1.9.0) 34 | builder 35 | excon (~> 0.14) 36 | formatador (~> 0.2.0) 37 | mime-types 38 | multi_json (~> 1.0) 39 | net-scp (~> 1.0.4) 40 | net-ssh (>= 2.1.3) 41 | nokogiri (~> 1.5.0) 42 | ruby-hmac 43 | formatador (0.2.4) 44 | gherkin (2.11.5) 45 | json (>= 1.4.6) 46 | grit (2.5.0) 47 | diff-lcs (~> 1.1) 48 | mime-types (~> 1.15) 49 | posix-spawn (~> 0.3.6) 50 | gssapi (1.0.3) 51 | ffi (>= 1.0.1) 52 | gyoku (1.0.0) 53 | builder (>= 2.1.2) 54 | highline (1.6.15) 55 | httpclient (2.2.0.2) 56 | httpi (0.9.7) 57 | rack 58 | i18n (0.6.1) 59 | json (1.5.4) 60 | libxml-ruby (2.4.0) 61 | little-plugger (1.1.3) 62 | log4r (1.1.10) 63 | logging (1.6.2) 64 | little-plugger (>= 1.1.3) 65 | mime-types (1.19) 66 | mixlib-log (1.4.1) 67 | multi_json (1.5.0) 68 | net-scp (1.0.4) 69 | net-ssh (>= 1.99.1) 70 | net-ssh (2.2.2) 71 | nokogiri (1.5.6) 72 | nori (1.1.4) 73 | open4 (1.3.0) 74 | popen4 (0.1.2) 75 | Platform (>= 0.4.0) 76 | open4 (>= 0.4.0) 77 | posix-spawn (0.3.6) 78 | progressbar (0.12.0) 79 | rack (1.4.4) 80 | rake (10.0.3) 81 | rspec (2.12.0) 82 | rspec-core (~> 2.12.0) 83 | rspec-expectations (~> 2.12.0) 84 | rspec-mocks (~> 2.12.0) 85 | rspec-core (2.12.2) 86 | rspec-expectations (2.12.1) 87 | diff-lcs (~> 1.1.3) 88 | rspec-mocks (2.12.1) 89 | ruby-hmac (0.4.0) 90 | ruby-vnc (1.0.1) 91 | rubyntlm (0.1.1) 92 | savon (0.9.5) 93 | akami (~> 1.0) 94 | builder (>= 2.1.2) 95 | gyoku (>= 0.4.0) 96 | httpi (~> 0.9) 97 | nokogiri (>= 1.4.0) 98 | nori (~> 1.0) 99 | wasabi (~> 1.0) 100 | thor (0.16.0) 101 | uuidtools (2.1.3) 102 | vagrant (1.0.5) 103 | archive-tar-minitar (= 0.5.2) 104 | childprocess (~> 0.3.1) 105 | erubis (~> 2.7.0) 106 | i18n (~> 0.6.0) 107 | json (~> 1.5.1) 108 | log4r (~> 1.1.9) 109 | net-scp (~> 1.0.4) 110 | net-ssh (~> 2.2.2) 111 | vagrant-windows (0.1.2) 112 | highline 113 | vagrant (~> 1.0.3) 114 | winrm (~> 1.1.1) 115 | veewee (0.3.7) 116 | ansi (~> 1.3.0) 117 | childprocess 118 | cucumber (>= 1.0.0) 119 | fission (= 0.4.0) 120 | fog (~> 1.8) 121 | grit 122 | highline 123 | i18n 124 | net-ssh (~> 2.2.0) 125 | popen4 (~> 0.1.2) 126 | progressbar 127 | rspec (~> 2.5) 128 | ruby-vnc (~> 1.0.0) 129 | thor (~> 0.15) 130 | vagrant (>= 0.9) 131 | wasabi (1.0.0) 132 | nokogiri (>= 1.4.0) 133 | winrm (1.1.2) 134 | gssapi (~> 1.0.0) 135 | httpclient (~> 2.2.0.2) 136 | logging (~> 1.6.1) 137 | nokogiri (~> 1.5.0) 138 | rubyntlm (~> 0.1.1) 139 | savon (= 0.9.5) 140 | uuidtools (~> 2.1.2) 141 | 142 | PLATFORMS 143 | ruby 144 | 145 | DEPENDENCIES 146 | em-winrm 147 | vagrant-windows 148 | veewee 149 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/README.md: -------------------------------------------------------------------------------- 1 | Description 2 | =========== 3 | 4 | Creates a configured handler path for distributing [Chef report and exception handlers](http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers). Also exposes an LWRP for enabling Chef handlers from within recipe code (as opposed to hard coding in the client.rb file). This is useful for cookbook authors who may want to ship a product specific handler (see the `cloudkick` cookbook for an example) with their cookbook. 5 | 6 | Attributes 7 | ========== 8 | 9 | `node["chef_handler"]["handler_path"]` - location to drop off handlers directory, default is `/var/chef/handlers`. 10 | 11 | Resource/Provider 12 | ================= 13 | 14 | `chef_handler` 15 | -------------- 16 | 17 | Requires, configures and enables handlers on the node for the current Chef run. Also has the ability to pass arguments to the handlers initializer. This allows initialization data to be pulled from a node's attribute data. 18 | 19 | It is best to declare `chef_handler` resources early on in the compile phase so they are available to fire for any exceptions during the Chef run. If you have a base role you would want any recipes that register Chef handlers to come first in the run_list. 20 | 21 | ### Actions 22 | 23 | - :enable: Enables the Chef handler for the current Chef run on the current node 24 | - :disable: Disables the Chef handler for the current Chef run on the current node 25 | 26 | ### Attribute Parameters 27 | 28 | - class_name: name attribute. The name of the handler class (can be module name-spaced). 29 | - source: full path to the handler file. can also be a gem path if the handler ships as part of a Ruby gem. 30 | - arguments: an array of arguments to pass the handler's class initializer 31 | - supports: type of Chef Handler to register as, ie :report, :exception or both. default is `:report => true, :exception => true` 32 | 33 | ### Example 34 | 35 | # register the Chef::Handler::JsonFile handler 36 | # that ships with the Chef gem 37 | chef_handler "Chef::Handler::JsonFile" do 38 | source "chef/handler/json_file" 39 | arguments :path => '/var/chef/reports' 40 | action :enable 41 | end 42 | 43 | # do the same but during the compile phase 44 | chef_handler "Chef::Handler::JsonFile" do 45 | source "chef/handler/json_file" 46 | arguments :path => '/var/chef/reports' 47 | action :nothing 48 | end.run_action(:enable) 49 | 50 | # handle exceptions only 51 | chef_handler "Chef::Handler::JsonFile" do 52 | source "chef/handler/json_file" 53 | arguments :path => '/var/chef/reports' 54 | supports :exception => true 55 | action :enable 56 | end 57 | 58 | 59 | # enable the CloudkickHandler which was 60 | # dropped off in the default handler path. 61 | # passes the oauth key/secret to the handler's 62 | # intializer. 63 | chef_handler "CloudkickHandler" do 64 | source "#{node['chef_handler']['handler_path']}/cloudkick_handler.rb" 65 | arguments [node['cloudkick']['oauth_key'], node['cloudkick']['oauth_secret']] 66 | action :enable 67 | end 68 | 69 | 70 | Usage 71 | ===== 72 | 73 | default 74 | ------- 75 | 76 | Put the recipe `chef_handler` at the start of the node's run list to make sure that custom handlers are dropped off early on in the Chef run and available for later recipes. 77 | 78 | For information on how to write report and exception handlers for Chef, please see the Chef wiki pages: 79 | http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers 80 | 81 | json_file 82 | --------- 83 | 84 | Leverages the `chef_handler` LWRP to automatically register the `Chef::Handler::JsonFile` handler that ships as part of Chef. This handler serializes the run status data to a JSON file located at `/var/chef/reports`. 85 | 86 | License and Author 87 | ================== 88 | 89 | Author:: Seth Chisamore () 90 | 91 | Copyright:: 2011, Opscode, Inc 92 | 93 | Licensed under the Apache License, Version 2.0 (the "License"); 94 | you may not use this file except in compliance with the License. 95 | You may obtain a copy of the License at 96 | 97 | http://www.apache.org/licenses/LICENSE-2.0 98 | 99 | Unless required by applicable law or agreed to in writing, software 100 | distributed under the License is distributed on an "AS IS" BASIS, 101 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 102 | See the License for the specific language governing permissions and 103 | limitations under the License. 104 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chef_handler", 3 | "description": "Distribute and enable Chef Exception and Report handlers", 4 | "long_description": "Description\n===========\n\nCreates a configured handler path for distributing [Chef report and exception handlers](http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers). Also exposes an LWRP for enabling Chef handlers from within recipe code (as opposed to hard coding in the client.rb file). This is useful for cookbook authors who may want to ship a product specific handler (see the `cloudkick` cookbook for an example) with their cookbook.\n\nAttributes\n==========\n\n`node[\"chef_handler\"][\"handler_path\"]` - location to drop off handlers directory, default is `/var/chef/handlers`.\n\nResource/Provider\n=================\n\n`chef_handler`\n--------------\n\nRequires, configures and enables handlers on the node for the current Chef run. Also has the ability to pass arguments to the handlers initializer. This allows initialization data to be pulled from a node's attribute data.\n\nIt is best to declare `chef_handler` resources early on in the compile phase so they are available to fire for any exceptions during the Chef run. If you have a base role you would want any recipes that register Chef handlers to come first in the run_list.\n\n### Actions\n\n- :enable: Enables the Chef handler for the current Chef run on the current node\n- :disable: Disables the Chef handler for the current Chef run on the current node\n\n### Attribute Parameters\n\n- class_name: name attribute. The name of the handler class (can be module name-spaced).\n- source: full path to the handler file. can also be a gem path if the handler ships as part of a Ruby gem.\n- arguments: an array of arguments to pass the handler's class initializer\n- supports: type of Chef Handler to register as, ie :report, :exception or both. default is `:report => true, :exception => true`\n\n### Example\n\n # register the Chef::Handler::JsonFile handler\n # that ships with the Chef gem\n chef_handler \"Chef::Handler::JsonFile\" do\n source \"chef/handler/json_file\"\n arguments :path => '/var/chef/reports'\n action :enable\n end\n\n # do the same but during the compile phase\n chef_handler \"Chef::Handler::JsonFile\" do\n source \"chef/handler/json_file\"\n arguments :path => '/var/chef/reports'\n action :nothing\n end.run_action(:enable)\n\n # handle exceptions only\n chef_handler \"Chef::Handler::JsonFile\" do\n source \"chef/handler/json_file\"\n arguments :path => '/var/chef/reports'\n supports :exception => true\n action :enable\n end\n\n\n # enable the CloudkickHandler which was\n # dropped off in the default handler path.\n # passes the oauth key/secret to the handler's\n # intializer.\n chef_handler \"CloudkickHandler\" do\n source \"#{node['chef_handler']['handler_path']}/cloudkick_handler.rb\"\n arguments [node['cloudkick']['oauth_key'], node['cloudkick']['oauth_secret']]\n action :enable\n end\n\n\nUsage\n=====\n\ndefault\n-------\n\nPut the recipe `chef_handler` at the start of the node's run list to make sure that custom handlers are dropped off early on in the Chef run and available for later recipes.\n\nFor information on how to write report and exception handlers for Chef, please see the Chef wiki pages:\nhttp://wiki.opscode.com/display/chef/Exception+and+Report+Handlers\n\njson_file\n---------\n\nLeverages the `chef_handler` LWRP to automatically register the `Chef::Handler::JsonFile` handler that ships as part of Chef. This handler serializes the run status data to a JSON file located at `/var/chef/reports`.\n\nLicense and Author\n==================\n\nAuthor:: Seth Chisamore ()\n\nCopyright:: 2011, Opscode, 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", 5 | "maintainer": "Opscode, Inc.", 6 | "maintainer_email": "cookbooks@opscode.com", 7 | "license": "Apache 2.0", 8 | "platforms": { 9 | }, 10 | "dependencies": { 11 | }, 12 | "recommendations": { 13 | }, 14 | "suggestions": { 15 | }, 16 | "conflicting": { 17 | }, 18 | "providing": { 19 | }, 20 | "replacing": { 21 | }, 22 | "attributes": { 23 | }, 24 | "groupings": { 25 | }, 26 | "recipes": { 27 | }, 28 | "version": "1.0.8" 29 | } -------------------------------------------------------------------------------- /cookbooks/windows/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Future 2 | 3 | * package preseeding/response_file support 4 | * package installation location via a `target_dir` attribute. 5 | * [COOK-666] `windows_package` should support CoApp packages 6 | * windows_registry :force_modify action should use RegNotifyChangeKeyValue from WinAPI 7 | * WindowsRebootHandler/`windows_reboot` LWRP should support kicking off subsequent chef run on reboot. 8 | * Support all types of registry keys with `type` parameter in `windows_registry`. 9 | 10 | ## v1.3.4: 11 | 12 | * [COOK-1173] - windows_registry throws Win32::Registry::Error for 13 | action :remove on a nonexistent key 14 | * [COOK-1182] - windows package sets start window title instead of 15 | quoting a path 16 | * [COOK-1476] - zipfile lwrp should support :zip action 17 | * [COOK-1485] - package resource fails to perform install correctly 18 | when "source" contains quote 19 | * [COOK-1519] - add action :remove for path lwrp 20 | 21 | ## v1.3.2: 22 | 23 | * [COOK-1033] - remove the `libraries/ruby_19_patches.rb` file which 24 | causes havoc on non-Windows systems. 25 | * [COOK-811] - add a timeout parameter attribute for `windows_package` 26 | 27 | ## v1.3.0: 28 | 29 | * [COOK-1323] - Update for changes in Chef 0.10.10. 30 | - Setting file mode doesn't make sense on Windows (package provider 31 | - and reboot_handler recipe) 32 | - Prefix ::Win32 to avoid namespace collision with Chef::Win32 33 | - (registry_helper library) 34 | - Use chef_gem instead of gem_package so gems get installed correctly 35 | under the Ruby environment Chef runs in (reboot_handler recipe, 36 | zipfile provider) 37 | 38 | ## v1.2.12: 39 | 40 | * [COOK-1037] - specify version for rubyzip gem 41 | * [COOK-1007] - windows_feature does not work to remove features with 42 | dism 43 | * [COOK-667] - shortcut resource + provider for Windows platforms 44 | 45 | ## v1.2.10 46 | 47 | * [COOK-939] - add `type` parameter to `windows_registry` to allow binary registry keys. 48 | * [COOK-940] - refactor logic so multiple values get created. 49 | 50 | ## v1.2.8 51 | 52 | * FIX: Older Windows (Windows Server 2003) sometimes return 127 on successful forked commands 53 | * FIX: `windows_package`, ensure we pass the WOW* registry redirection flags into reg.open 54 | 55 | ## v1.2.6 56 | 57 | * patch to fix [CHEF-2684], Open4 is named Open3 in Ruby 1.9 58 | * Ruby 1.9's Open3 returns 0 and 42 for successful commands 59 | * retry keyword can only be used in a rescue block in Ruby 1.9 60 | 61 | ## v1.2.4 62 | 63 | * windows_package - catch Win32::Registry::Error that pops up when searching certain keys 64 | 65 | ## v1.2.2 66 | 67 | * combined numerous helper libarires for easier sharing across libaries/LWRPs 68 | * renamed Chef::Provider::WindowsFeature::Base file to the more descriptive `feature_base.rb` 69 | * refactored windows_path LWRP 70 | * :add action should MODIFY the the underlying ENV variable (vs CREATE) 71 | * deleted greedy :remove action until it could be made more idempotent 72 | * added a windows_batch resource/provider for running batch scripts remotely 73 | 74 | ## v1.2.0 75 | 76 | * [COOK-745] gracefully handle required server restarts on Windows platform 77 | * WindowsRebootHandler for requested and pending reboots 78 | * windows_reboot LWRP for requesting (receiving notifies) reboots 79 | * reboot_handler recipe for enabling WindowsRebootHandler as a report handler 80 | * [COOK-714] Correct initialize misspelling 81 | * RegistryHelper - new `get_values` method which returns all values for a particular key. 82 | 83 | ## v1.0.8 84 | 85 | * [COOK-719] resource/provider for managing windows features 86 | * [COOK-717] remove `windows_env_vars` resource as env resource exists in core chef 87 | * new `Windows::Version` helper class 88 | * refactored `Windows::Helper` mixin 89 | 90 | ## v1.0.6 91 | 92 | * added `force_modify` action to `windows_registry` resource 93 | * add `win_friendly_path` helper 94 | * re-purpose default recipe to install useful supporting windows related gems 95 | 96 | ## v1.0.4 97 | 98 | * [COOK-700] new resources and improvements to the `windows_registry` provider (thanks Paul Morton!) 99 | * Open the registry in the bitednes of the OS 100 | * Provide convenience methods to check if keys and values exit 101 | * Provide convenience method for reading registry values 102 | * NEW - `windows_auto_run` resource/provider 103 | * NEW - `windows_env_vars` resource/provider 104 | * NEW - `windows_path` resource/provider 105 | * re-write of the windows_package logic for determining current installed packages 106 | * new checksum attribute for windows_package resource...useful for remote packages 107 | 108 | ## v1.0.2: 109 | 110 | * [COOK-647] account for Wow6432Node registry redirecter 111 | * [COOK-656] begin/rescue on win32/registry 112 | 113 | ## 1.0.0: 114 | 115 | * [COOK-612] initial release 116 | -------------------------------------------------------------------------------- /cookbooks/windows-fromscratch/recipes/_ie_annoyances.rb: -------------------------------------------------------------------------------- 1 | # http://technet.microsoft.com/en-us/library/cc732131.aspx 2 | # Look upnder Registry settings 3 | 4 | 5 | # (see http://support.microsoft.com/kb/182569/#letmefixit) 6 | insecure_zone = { 7 | '1001' => 0, 8 | '1004' => 0, 9 | '1200' => 0, 10 | '1201' => 0, 11 | '1400' => 0, 12 | '1402' => 0, 13 | '1405' => 0, 14 | '1406' => 0, 15 | '1601' => 0, 16 | '1604' => 0, 17 | '1609' => 0, 18 | '1605' => 0, 19 | '1607' => 0, 20 | '1809' => 3, 21 | '2101' => 0, 22 | '2102' => 0, 23 | '2105' => 0, 24 | '2301' => 3, 25 | '2500' => 0, 26 | 'CurrentLevel' => 10500, 27 | "WarnOnHTTPSToHTTPRedirect" => 0, 28 | "WarnOnPost" => 0, 29 | "WarnOnPostRedirect" => 0, 30 | "WarnOnZoneCrossing" => 0, 31 | "WarnonBadCertRecving" => 0 32 | } 33 | 34 | { 35 | 'HKCU\Software\Microsoft\Internet Explorer\InformationBar' => {'FirstTime' => 0}, 36 | 'HKCU\Software\Microsoft\Internet Explorer\Security' => {'DisableSecuritySettingsCheck' => 1}, 37 | 'HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1' => insecure_zone, 38 | 'HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2' => insecure_zone, 39 | 'HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3' => insecure_zone, 40 | 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\tips' => {'Show' => 0}, 41 | 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced' => { 42 | "StartButtonBalloonTip" => 0, 43 | "ShowInfoTip" => 0, 44 | "EnableBalloonTips" => 0, 45 | "FolderContentsInfoTip" => 0 46 | }, 47 | 'HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer' => {'NoSMBalloonTip' => 0}, 48 | # Force IE to open Selenium in a window and not a tab 49 | 'HKCU\Software\Microsoft\Internet Explorer\TabbedBrowsing' => { 50 | "Enabled" => 1, 51 | "WarnOnClose" => 0, 52 | "OpenInForeground" => 0, 53 | "PopupsUseNewWindow" => 1 54 | }, 55 | # Bump IE 6 and 7 max synchronous requests 56 | 'HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings' => { 57 | "MaxConnectionsPer1_0Server" => 15, 58 | "MaxConnectionsPerServer" => 15, 59 | # Disable HTTPS->HTTP warning dialogue in IE on POST redirect 60 | # (see http://ie7triage.spaces.live.com/blog/cns!3B6634EF5458F389!240.entry) 61 | "WarnOnPostRedirect" => 0, 62 | "WarnOnIntranet" => 0, 63 | "WarnOnPost" => 0, 64 | "WarnonZoneCrossing" => 0, 65 | "WarnonBadCertRecving" => 0, 66 | "WarnOnPostRedirect" => 0, 67 | "DisableCachingOfSSLPages" => 0, 68 | }, 69 | 70 | 'HKCU\Software\Microsoft\Internet Explorer\Main' => { 71 | "Check_Associations" => "no", # Disable default browser check 72 | "Start Page" => "about:blank", # Setting start page 73 | "FormSuggest Passwords" => "no", 74 | "FormSuggest PW Ask" => "no", 75 | "Use FormSuggest" => "no" 76 | }, 77 | 78 | 'HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\WindowsSearch' => { 79 | "AutoCompleteGroups" => 1, 80 | "EnabledScopes" => 1 81 | }, 82 | 83 | 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoComplete' => { 84 | "AutoSuggest"=>"yes" 85 | }, 86 | 87 | 'HKLM\Software\Policies\Microsoft\Internet Explorer\Main' => { 88 | 'DisableFirstRunCustomize' => 1 89 | }, 90 | 'HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}' => { 91 | 'IsInstalled' => 0 92 | }, 93 | 'HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}' => { 94 | 'IsInstalled' => 0 95 | } 96 | #Disable taskbar/system tray/start menu stuff 97 | # 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer' => { 98 | # "NoTrayItemsDisplay" => 1, 99 | # "NoStartMenuPinnedList" => 1, 100 | # "NoStartMenuMFUprogramsList" => 1, 101 | # "NoStartMenuMorePrograms" => 1, 102 | # "NoCommonGroups" => 1, 103 | # "GreyMSIAds" => 1, 104 | # "NoWindowsUpdate" => 1, 105 | # "NoStartMenuMyMusic" => 1, 106 | # "NoSMMyPictures" => 1, 107 | # "NoFavoritesMenu" => 1, 108 | # "NoRecentDocsMenu" => 1, 109 | # "DisableMyPicturesDirChange" => 1, 110 | # "DisableMyMusicDirChange" => 1, 111 | # "DisableFavoritesDirChange" => 1, 112 | # "NoSMMyDocs" => 1, 113 | # "DisablePersonalDirChange" => 1, 114 | # "NoRecentDocsMenu" => 1, 115 | # "NoFavoritesMenu" => 1, 116 | # "NoNetworkConnections" => 1, 117 | # "NoStartMenuNetworkPlaces" => 1, 118 | # "NoRecentDocsNetHood" => 1, 119 | # "NoSMHelp" => 1, 120 | # "NoFind" => 1, 121 | # "NoRun" => 1, 122 | # "NoResolveSearch" => 1, 123 | # "NoResolveTrack" => 1, 124 | # "StartMenuLogoff" => 1, 125 | # "NoClose" => 1, 126 | # "NoStartMenuEjectPC" => 1, 127 | # "NoChangeStartMenu" => 1, 128 | # "NoSetTaskbar" => 1, 129 | # "NoUserNameInStartMenu" => 1 130 | # } 131 | }.each do |regpath,entries| 132 | windows_registry regpath do 133 | values entries 134 | end 135 | end 136 | 137 | -------------------------------------------------------------------------------- /cookbooks/windows/providers/package.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Provider:: package 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 | if RUBY_PLATFORM =~ /mswin|mingw32|windows/ 22 | require 'win32/registry' 23 | end 24 | 25 | require 'chef/mixin/shell_out' 26 | require 'chef/mixin/language' 27 | 28 | include Chef::Mixin::ShellOut 29 | include Windows::Helper 30 | 31 | # the logic in all action methods mirror that of 32 | # the Chef::Provider::Package which will make 33 | # refactoring into core chef easy 34 | 35 | action :install do 36 | # If we specified a version, and it's not the current version, move to the specified version 37 | if @new_resource.version != nil && @new_resource.version != @current_resource.version 38 | install_version = @new_resource.version 39 | # If it's not installed at all, install it 40 | elsif @current_resource.version == nil 41 | install_version = candidate_version 42 | end 43 | 44 | if install_version 45 | Chef::Log.info("Installing #{@new_resource} version #{install_version}") 46 | status = install_package(@new_resource.package_name, install_version) 47 | if status 48 | @new_resource.updated_by_last_action(true) 49 | end 50 | end 51 | end 52 | 53 | action :upgrade do 54 | if @current_resource.version != candidate_version 55 | orig_version = @current_resource.version || "uninstalled" 56 | Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}") 57 | status = upgrade_package(@new_resource.package_name, candidate_version) 58 | if status 59 | @new_resource.updated_by_last_action(true) 60 | end 61 | end 62 | end 63 | 64 | action :remove do 65 | if removing_package? 66 | Chef::Log.info("Removing #{@new_resource}") 67 | remove_package(@current_resource.package_name, @new_resource.version) 68 | @new_resource.updated_by_last_action(true) 69 | else 70 | end 71 | end 72 | 73 | def removing_package? 74 | if @current_resource.version.nil? 75 | false # nothing to remove 76 | elsif @new_resource.version.nil? 77 | true # remove any version of a package 78 | elsif @new_resource.version == @current_resource.version 79 | true # remove the version we have 80 | else 81 | false # we don't have the version we want to remove 82 | end 83 | end 84 | 85 | def expand_options(options) 86 | options ? " #{options}" : "" 87 | end 88 | 89 | # these methods are the required overrides of 90 | # a provider that extends from Chef::Provider::Package 91 | # so refactoring into core Chef should be easy 92 | 93 | def load_current_resource 94 | @current_resource = Chef::Resource::WindowsPackage.new(@new_resource.name) 95 | @current_resource.package_name(@new_resource.package_name) 96 | @current_resource.version(nil) 97 | 98 | unless current_installed_version.nil? 99 | @current_resource.version(current_installed_version) 100 | end 101 | 102 | @current_resource 103 | end 104 | 105 | def current_installed_version 106 | @current_installed_version ||= begin 107 | if installed_packages.include?(@new_resource.package_name) 108 | installed_packages[@new_resource.package_name][:version] 109 | end 110 | end 111 | end 112 | 113 | def candidate_version 114 | @candidate_version ||= begin 115 | @new_resource.version || 'latest' 116 | end 117 | end 118 | 119 | def install_package(name,version) 120 | Chef::Log.debug("Processing #{@new_resource} as a #{installer_type} installer.") 121 | install_args = [cached_file(@new_resource.source, @new_resource.checksum), expand_options(unattended_installation_flags), expand_options(@new_resource.options)] 122 | Chef::Log.info("Starting installation...this could take awhile.") 123 | shell_out!(sprintf(install_command_template, *install_args), {:timeout => @new_resource.timeout, :returns => [0,42,127]}) 124 | end 125 | 126 | def remove_package(name, version) 127 | uninstall_string = installed_packages[@new_resource.package_name][:uninstall_string] 128 | Chef::Log.info("Registry provided uninstall string for #{@new_resource} is '#{uninstall_string}'") 129 | uninstall_command = begin 130 | if uninstall_string =~ /msiexec/i 131 | "#{uninstall_string} /qn" 132 | else 133 | uninstall_string.gsub!('"','') 134 | "start \"\" /wait /d\"#{::File.dirname(uninstall_string)}\" #{::File.basename(uninstall_string)}#{expand_options(@new_resource.options)} /S" 135 | end 136 | end 137 | Chef::Log.info("Removing #{@new_resource} with uninstall command '#{uninstall_command}'") 138 | shell_out!(uninstall_command, {:returns => [0,42,127]}) 139 | end 140 | 141 | private 142 | 143 | def install_command_template 144 | case installer_type 145 | when :msi 146 | "msiexec%2$s %1$s%3$s" 147 | else 148 | "start \"\" /wait %1$s%2$s%3$s" 149 | end 150 | end 151 | 152 | def uninstall_command_template 153 | case installer_type 154 | when :msi 155 | "msiexec %2$s %1$s" 156 | else 157 | "start \"\" /wait /d%1$s %2$s %3$s" 158 | end 159 | end 160 | 161 | # http://unattended.sourceforge.net/installers.php 162 | def unattended_installation_flags 163 | case installer_type 164 | when :msi 165 | "/qb /i" 166 | when :installshield 167 | "/s /sms" 168 | when :nsis 169 | "/S /NCRC" 170 | when :inno 171 | #"/sp- /silent /norestart" 172 | "/verysilent /norestart" 173 | when :wise 174 | "/s" 175 | else 176 | end 177 | end 178 | 179 | def installed_packages 180 | @installed_packages || begin 181 | installed_packages = {} 182 | # Computer\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall 183 | installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_LOCAL_MACHINE)) #rescue nil 184 | # 64-bit registry view 185 | # Computer\HKEY_LOCAL_MACHINE\Software\Wow6464Node\Microsoft\Windows\CurrentVersion\Uninstall 186 | installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0100))) #rescue nil 187 | # 32-bit registry view 188 | # Computer\HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall 189 | installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0200))) #rescue nil 190 | # Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall 191 | installed_packages.merge!(extract_installed_packages_from_key(::Win32::Registry::HKEY_CURRENT_USER)) #rescue nil 192 | installed_packages 193 | end 194 | end 195 | 196 | def extract_installed_packages_from_key(hkey = ::Win32::Registry::HKEY_LOCAL_MACHINE, desired = ::Win32::Registry::Constants::KEY_READ) 197 | uninstall_subkey = 'Software\Microsoft\Windows\CurrentVersion\Uninstall' 198 | packages = {} 199 | begin 200 | ::Win32::Registry.open(hkey, uninstall_subkey, desired) do |reg| 201 | reg.each_key do |key, wtime| 202 | begin 203 | k = reg.open(key, desired) 204 | display_name = k["DisplayName"] rescue nil 205 | version = k["DisplayVersion"] rescue "NO VERSION" 206 | uninstall_string = k["UninstallString"] rescue nil 207 | if display_name 208 | packages[display_name] = {:name => display_name, 209 | :version => version, 210 | :uninstall_string => uninstall_string} 211 | end 212 | rescue ::Win32::Registry::Error 213 | end 214 | end 215 | end 216 | rescue ::Win32::Registry::Error 217 | end 218 | packages 219 | end 220 | 221 | def installer_type 222 | @installer_type || begin 223 | if @new_resource.installer_type 224 | @new_resource.installer_type 225 | else 226 | basename = ::File.basename(cached_file(@new_resource.source)) 227 | if basename.split(".").last == "msi" # Microsoft MSI 228 | :msi 229 | else 230 | # search the binary file for installer type 231 | contents = ::Kernel.open(::File.expand_path(cached_file(@new_resource.source)), "rb") {|io| io.read } # TODO limit data read in 232 | case contents 233 | when /inno/i # Inno Setup 234 | :inno 235 | when /wise/i # Wise InstallMaster 236 | :wise 237 | when /nsis/i # Nullsoft Scriptable Install System 238 | :nsis 239 | else 240 | # if file is named 'setup.exe' assume installshield 241 | if basename == "setup.exe" 242 | :installshield 243 | else 244 | raise Chef::Exceptions::AttributeNotFound, "installer_type could not be determined, please set manually" 245 | end 246 | end 247 | end 248 | end 249 | end 250 | end 251 | -------------------------------------------------------------------------------- /cookbooks/windows/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /cookbooks/chef_handler/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /cookbooks/windows/libraries/registry_helper.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Doug MacEachern () 3 | # Author:: Seth Chisamore () 4 | # Author:: Paul Morton () 5 | # Cookbook Name:: windows 6 | # Provider:: registry 7 | # 8 | # Copyright:: 2010, VMware, Inc. 9 | # Copyright:: 2011, Opscode, Inc. 10 | # Copyright:: 2011, Business Intelligence Associates, Inc 11 | # 12 | # Licensed under the Apache License, Version 2.0 (the "License"); 13 | # you may not use this file except in compliance with the License. 14 | # You may obtain a copy of the License at 15 | # 16 | # http://www.apache.org/licenses/LICENSE-2.0 17 | # 18 | # Unless required by applicable law or agreed to in writing, software 19 | # distributed under the License is distributed on an "AS IS" BASIS, 20 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | # See the License for the specific language governing permissions and 22 | # limitations under the License. 23 | # 24 | 25 | if RUBY_PLATFORM =~ /mswin|mingw32|windows/ 26 | require 'win32/registry' 27 | require 'ruby-wmi' 28 | end 29 | 30 | module Windows 31 | module RegistryHelper 32 | 33 | @@native_registry_constant = ENV['PROCESSOR_ARCHITEW6432'] == 'AMD64' ? 0x0100 : 0x0200 34 | 35 | def get_hive_name(path) 36 | Chef::Log.debug("Resolving registry shortcuts to full names") 37 | 38 | reg_path = path.split("\\") 39 | hive_name = reg_path.shift 40 | 41 | hkey = { 42 | "HKLM" => "HKEY_LOCAL_MACHINE", 43 | "HKCU" => "HKEY_CURRENT_USER", 44 | "HKU" => "HKEY_USERS" 45 | }[hive_name] || hive_name 46 | 47 | Chef::Log.debug("Hive resolved to #{hkey}") 48 | return hkey 49 | end 50 | 51 | def get_hive(path) 52 | 53 | Chef::Log.debug("Getting hive for #{path}") 54 | reg_path = path.split("\\") 55 | hive_name = reg_path.shift 56 | 57 | hkey = get_hive_name(path) 58 | 59 | hive = { 60 | "HKEY_LOCAL_MACHINE" => ::Win32::Registry::HKEY_LOCAL_MACHINE, 61 | "HKEY_USERS" => ::Win32::Registry::HKEY_USERS, 62 | "HKEY_CURRENT_USER" => ::Win32::Registry::HKEY_CURRENT_USER 63 | }[hkey] 64 | 65 | unless hive 66 | Chef::Application.fatal!("Unsupported registry hive '#{hive_name}'") 67 | end 68 | 69 | 70 | Chef::Log.debug("Registry hive resolved to #{hkey}") 71 | return hive 72 | end 73 | 74 | def unload_hive(path) 75 | hive = get_hive(path) 76 | if hive == ::Win32::Registry::HKEY_USERS 77 | reg_path = path.split("\\") 78 | priv = Chef::WindowsPrivileged.new 79 | begin 80 | priv.reg_unload_key(reg_path[1]) 81 | rescue 82 | end 83 | end 84 | end 85 | 86 | def set_value(mode,path,values,type=nil) 87 | hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path) 88 | key_name = reg_path.join("\\") 89 | 90 | Chef::Log.debug("Creating #{path}") 91 | 92 | if !key_exists?(path,true) 93 | create_key(path) 94 | end 95 | 96 | hive.send(mode, key_name, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do |reg| 97 | changed_something = false 98 | values.each do |k,val| 99 | key = "#{k}" #wtf. avoid "can't modify frozen string" in win32/registry.rb 100 | cur_val = nil 101 | begin 102 | cur_val = reg[key] 103 | rescue 104 | #subkey does not exist (ok) 105 | end 106 | if cur_val != val 107 | Chef::Log.debug("setting #{key}=#{val}") 108 | if type.nil? 109 | reg[key] = val 110 | else 111 | reg[key, ::Win32::Registry::REG_BINARY] = val 112 | end 113 | 114 | ensure_hive_unloaded(hive_loaded) 115 | 116 | changed_something = true 117 | end 118 | end 119 | return changed_something 120 | end 121 | return false 122 | end 123 | 124 | def get_value(path,value) 125 | hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path) 126 | key = reg_path.join("\\") 127 | 128 | hive.open(key, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do | reg | 129 | begin 130 | return reg[value] 131 | rescue 132 | return nil 133 | ensure 134 | ensure_hive_unloaded(hive_loaded) 135 | end 136 | end 137 | end 138 | 139 | def get_values(path) 140 | hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path) 141 | key = reg_path.join("\\") 142 | hive.open(key, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do | reg | 143 | values = [] 144 | begin 145 | reg.each_value do |name, type, data| 146 | values << [name, type, data] 147 | end 148 | rescue 149 | ensure 150 | ensure_hive_unloaded(hive_loaded) 151 | end 152 | values 153 | end 154 | end 155 | 156 | def delete_value(path,values) 157 | hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path) 158 | key = reg_path.join("\\") 159 | Chef::Log.debug("Deleting values in #{path}") 160 | hive.open(key, ::Win32::Registry::KEY_ALL_ACCESS | @@native_registry_constant) do | reg | 161 | values.each_key { |key| 162 | name = "#{key}" 163 | # Ensure delete operation is idempotent. 164 | if value_exists?(path, key) 165 | Chef::Log.debug("Deleting value #{name} in #{path}") 166 | reg.delete_value(name) 167 | else 168 | Chef::Log.debug("Value #{name} in #{path} does not exist, skipping.") 169 | end 170 | } 171 | end 172 | 173 | end 174 | 175 | def create_key(path) 176 | hive, reg_path, hive_name, root_key, hive_loaded = get_reg_path_info(path) 177 | key = reg_path.join("\\") 178 | Chef::Log.debug("Creating registry key #{path}") 179 | hive.create(key) 180 | end 181 | 182 | def value_exists?(path,value) 183 | if key_exists?(path,true) 184 | 185 | hive, reg_path, hive_name, root_key , hive_loaded = get_reg_path_info(path) 186 | key = reg_path.join("\\") 187 | 188 | Chef::Log.debug("Attempting to open #{key}"); 189 | Chef::Log.debug("Native Constant #{@@native_registry_constant}") 190 | Chef::Log.debug("Hive #{hive}") 191 | 192 | hive.open(key, ::Win32::Registry::KEY_READ | @@native_registry_constant) do | reg | 193 | begin 194 | rtn_value = reg[value] 195 | return true 196 | rescue 197 | return false 198 | ensure 199 | ensure_hive_unloaded(hive_loaded) 200 | end 201 | end 202 | 203 | end 204 | return false 205 | end 206 | 207 | # TODO: Does not load user registry... 208 | def key_exists?(path, load_hive = false) 209 | if load_hive 210 | hive, reg_path, hive_name, root_key , hive_loaded = get_reg_path_info(path) 211 | key = reg_path.join("\\") 212 | else 213 | hive = get_hive(path) 214 | reg_path = path.split("\\") 215 | hive_name = reg_path.shift 216 | root_key = reg_path[0] 217 | key = reg_path.join("\\") 218 | hive_loaded = false 219 | end 220 | 221 | begin 222 | hive.open(key, ::Win32::Registry::Constants::KEY_READ | @@native_registry_constant ) 223 | return true 224 | rescue 225 | return false 226 | ensure 227 | ensure_hive_unloaded(hive_loaded) 228 | end 229 | end 230 | 231 | def get_user_hive_location(sid) 232 | reg_key = "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\#{sid}" 233 | Chef::Log.debug("Looking for profile at #{reg_key}") 234 | if key_exists?(reg_key) 235 | return get_value(reg_key,'ProfileImagePath') 236 | else 237 | return nil 238 | end 239 | 240 | end 241 | 242 | def resolve_user_to_sid(username) 243 | begin 244 | sid = WMI::Win32_UserAccount.find(:first, :conditions => {:name => username}).sid 245 | Chef::Log.debug("Resolved user SID to #{sid}") 246 | return sid 247 | rescue 248 | return nil 249 | end 250 | end 251 | 252 | def hive_loaded?(path) 253 | hive = get_hive(path) 254 | reg_path = path.split("\\") 255 | hive_name = reg_path.shift 256 | user_hive = path[0] 257 | 258 | if is_user_hive?(hive) 259 | return key_exists?("#{hive_name}\\#{user_hive}") 260 | else 261 | return true 262 | end 263 | end 264 | 265 | def is_user_hive?(hive) 266 | if hive == ::Win32::Registry::HKEY_USERS 267 | return true 268 | else 269 | return true 270 | end 271 | end 272 | 273 | def get_reg_path_info(path) 274 | hive = get_hive(path) 275 | reg_path = path.split("\\") 276 | hive_name = reg_path.shift 277 | root_key = reg_path[0] 278 | hive_loaded = false 279 | 280 | if is_user_hive?(hive) && !key_exists?("#{hive_name}\\#{root_key}") 281 | reg_path, hive_loaded = load_user_hive(hive,reg_path,root_key) 282 | root_key = reg_path[0] 283 | Chef::Log.debug("Resolved user (#{path}) to (#{reg_path.join('/')})") 284 | end 285 | 286 | return hive, reg_path, hive_name, root_key, hive_loaded 287 | end 288 | 289 | def load_user_hive(hive,reg_path,user_hive) 290 | Chef::Log.debug("Reg Path #{reg_path}") 291 | # See if the hive is loaded. Logged in users will have a key that is named their SID 292 | # if the user has specified the a path by SID and the user is logged in, this function 293 | # should not be executed. 294 | if is_user_hive?(hive) && !key_exists?("HKU\\#{user_hive}") 295 | Chef::Log.debug("The user is not logged in and has not been specified by SID") 296 | sid = resolve_user_to_sid(user_hive) 297 | Chef::Log.debug("User SID resolved to (#{sid})") 298 | # Now that the user has been resolved to a SID, check and see if the hive exists. 299 | # If this exists by SID, the user is logged in and we should use that key. 300 | # TODO: Replace the username with the sid and send it back because the username 301 | # does not exist as the key location. 302 | load_reg = false 303 | if key_exists?("HKU\\#{sid}") 304 | reg_path[0] = sid #use the active profile (user is logged on) 305 | Chef::Log.debug("HKEY_USERS Mapped: #{user_hive} -> #{sid}") 306 | else 307 | Chef::Log.debug("User is not logged in") 308 | load_reg = true 309 | end 310 | 311 | # The user is not logged in, so we should load the registry from disk 312 | if load_reg 313 | profile_path = get_user_hive_location(sid) 314 | if profile_path != nil 315 | ntuser_dat = "#{profile_path}\\NTUSER.DAT" 316 | if ::File.exists?(ntuser_dat) 317 | priv = Chef::WindowsPrivileged.new 318 | if priv.reg_load_key(sid,ntuser_dat) 319 | Chef::Log.debug("RegLoadKey(#{sid}, #{user_hive}, #{ntuser_dat})") 320 | reg_path[0] = sid 321 | else 322 | Chef::Log.debug("Failed RegLoadKey(#{sid}, #{user_hive}, #{ntuser_dat})") 323 | end 324 | end 325 | end 326 | end 327 | end 328 | 329 | return reg_path, load_reg 330 | 331 | end 332 | 333 | private 334 | def ensure_hive_unloaded(hive_loaded=false) 335 | if(hive_loaded) 336 | Chef::Log.debug("Hive was loaded, we really should unload it") 337 | unload_hive(path) 338 | end 339 | end 340 | end 341 | end 342 | 343 | module Registry 344 | module_function 345 | extend Windows::RegistryHelper 346 | end 347 | -------------------------------------------------------------------------------- /cookbooks/windows/libraries/version.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Author:: Seth Chisamore () 3 | # Cookbook Name:: windows 4 | # Library:: version 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 | if RUBY_PLATFORM =~ /mswin|mingw32|windows/ 22 | require 'ruby-wmi' 23 | require 'Win32API' 24 | end 25 | 26 | module Windows 27 | class Version 28 | 29 | # http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx 30 | 31 | # Suite Masks 32 | # Microsoft BackOffice components are installed. 33 | VER_SUITE_BACKOFFICE = 0x00000004 34 | # Windows Server 2003, Web Edition is installed. 35 | VER_SUITE_BLADE = 0x00000400 36 | # Windows Server 2003, Compute Cluster Edition is installed. 37 | VER_SUITE_COMPUTE_SERVER = 0x00004000 38 | # Windows Server 2008 Datacenter, Windows Server 2003, Datacenter Edition, or Windows 2000 Datacenter Server is installed. 39 | VER_SUITE_DATACENTER = 0x00000080 40 | # Windows Server 2008 Enterprise, Windows Server 2003, Enterprise Edition, or Windows 2000 Advanced Server is installed. Refer to the Remarks section for more information about this bit flag. 41 | VER_SUITE_ENTERPRISE = 0x00000002 42 | # Windows XP Embedded is installed. 43 | VER_SUITE_EMBEDDEDNT = 0x00000040 44 | # Windows Vista Home Premium, Windows Vista Home Basic, or Windows XP Home Edition is installed. 45 | VER_SUITE_PERSONAL = 0x00000200 46 | # Remote Desktop is supported, but only one interactive session is supported. This value is set unless the system is running in application server mode. 47 | VER_SUITE_SINGLEUSERTS = 0x00000100 48 | # Microsoft Small Business Server was once installed on the system, but may have been upgraded to another version of Windows. Refer to the Remarks section for more information about this bit flag. 49 | VER_SUITE_SMALLBUSINESS = 0x00000001 50 | # Microsoft Small Business Server is installed with the restrictive client license in force. Refer to the Remarks section for more information about this bit flag. 51 | VER_SUITE_SMALLBUSINESS_RESTRICTED = 0x00000020 52 | # Windows Storage Server 2003 R2 or Windows Storage Server 2003is installed. 53 | VER_SUITE_STORAGE_SERVER = 0x00002000 54 | # Terminal Services is installed. This value is always set. 55 | # If VER_SUITE_TERMINAL is set but VER_SUITE_SINGLEUSERTS is not set, the system is running in application server mode. 56 | VER_SUITE_TERMINAL = 0x00000010 57 | # Windows Home Server is installed. 58 | VER_SUITE_WH_SERVER = 0x00008000 59 | 60 | # Product Type 61 | # The system is a domain controller and the operating system is Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server. 62 | VER_NT_DOMAIN_CONTROLLER = 0x0000002 63 | # The operating system is Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, or Windows 2000 Server. 64 | # Note that a server that is also a domain controller is reported as VER_NT_DOMAIN_CONTROLLER, not VER_NT_SERVER. 65 | VER_NT_SERVER = 0x0000003 66 | # The operating system is Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional. 67 | VER_NT_WORKSTATION = 0x0000001 68 | 69 | # GetSystemMetrics 70 | # The build number if the system is Windows Server 2003 R2; otherwise, 0. 71 | SM_SERVERR2 = 89 72 | 73 | # http://msdn.microsoft.com/en-us/library/ms724358(v=vs.85).aspx 74 | # this is what it sounds like...when kittens die 75 | SKU = { 76 | 0x00000006 => {:ms_const => 'PRODUCT_BUSINESS', :name => 'Business'}, 77 | 0x00000010 => {:ms_const => 'PRODUCT_BUSINESS_N', :name => 'Business N'}, 78 | 0x00000012 => {:ms_const => 'PRODUCT_CLUSTER_SERVER', :name => 'HPC Edition'}, 79 | 0x00000008 => {:ms_const => 'PRODUCT_DATACENTER_SERVER', :name => 'Server Datacenter (full installation)'}, 80 | 0x0000000C => {:ms_const => 'PRODUCT_DATACENTER_SERVER_CORE', :name => 'Server Datacenter (core installation)'}, 81 | 0x00000027 => {:ms_const => 'PRODUCT_DATACENTER_SERVER_CORE_V', :name => 'Server Datacenter without Hyper-V (core installation)'}, 82 | 0x00000025 => {:ms_const => 'PRODUCT_DATACENTER_SERVER_V', :name => 'Server Datacenter without Hyper-V (full installation)'}, 83 | 0x00000004 => {:ms_const => 'PRODUCT_ENTERPRISE', :name => 'Enterprise'}, 84 | 0x00000046 => {:ms_const => 'PRODUCT_ENTERPRISE_E', :name => 'Not supported'}, 85 | 0x0000001B => {:ms_const => 'PRODUCT_ENTERPRISE_N', :name => 'Enterprise N'}, 86 | 0x0000000A => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER', :name => 'Server Enterprise (full installation)'}, 87 | 0x0000000E => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_CORE', :name => 'Server Enterprise (core installation)'}, 88 | 0x00000029 => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_CORE_V', :name => 'Server Enterprise without Hyper-V (core installation)'}, 89 | 0x0000000F => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_IA64', :name => 'Server Enterprise for Itanium-based Systems'}, 90 | 0x00000026 => {:ms_const => 'PRODUCT_ENTERPRISE_SERVER_V', :name => 'Server Enterprise without Hyper-V (full installation)'}, 91 | 0x00000002 => {:ms_const => 'PRODUCT_HOME_BASIC', :name => 'Home Basic'}, 92 | 0x00000043 => {:ms_const => 'PRODUCT_HOME_BASIC_E', :name => 'Not supported'}, 93 | 0x00000005 => {:ms_const => 'PRODUCT_HOME_BASIC_N', :name => 'Home Basic N'}, 94 | 0x00000003 => {:ms_const => 'PRODUCT_HOME_PREMIUM', :name => 'Home Premium'}, 95 | 0x00000044 => {:ms_const => 'PRODUCT_HOME_PREMIUM_E', :name => 'Not supported'}, 96 | 0x0000001A => {:ms_const => 'PRODUCT_HOME_PREMIUM_N', :name => 'Home Premium N'}, 97 | 0x0000002A => {:ms_const => 'PRODUCT_HYPERV', :name => 'Microsoft Hyper-V Server'}, 98 | 0x0000001E => {:ms_const => 'PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT', :name => 'Windows Essential Business Server Management Server'}, 99 | 0x00000020 => {:ms_const => 'PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING', :name => 'Windows Essential Business Server Messaging Server'}, 100 | 0x0000001F => {:ms_const => 'PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY', :name => 'Windows Essential Business Server Security Server'}, 101 | 0x00000030 => {:ms_const => 'PRODUCT_PROFESSIONAL', :name => 'Professional'}, 102 | 0x00000045 => {:ms_const => 'PRODUCT_PROFESSIONAL_E', :name => 'Not supported'}, 103 | 0x00000031 => {:ms_const => 'PRODUCT_PROFESSIONAL_N', :name => 'Professional N'}, 104 | 0x00000018 => {:ms_const => 'PRODUCT_SERVER_FOR_SMALLBUSINESS', :name => 'Windows Server 2008 for Windows Essential Server Solutions'}, 105 | 0x00000023 => {:ms_const => 'PRODUCT_SERVER_FOR_SMALLBUSINESS_V', :name => 'Windows Server 2008 without Hyper-V for Windows Essential Server Solutions'}, 106 | 0x00000021 => {:ms_const => 'PRODUCT_SERVER_FOUNDATION', :name => 'Server Foundation'}, 107 | 0x00000022 => {:ms_const => 'PRODUCT_HOME_PREMIUM_SERVER', :name => 'Windows Home Server 2011'}, 108 | 0x00000032 => {:ms_const => 'PRODUCT_SB_SOLUTION_SERVER', :name => 'Windows Small Business Server 2011 Essentials'}, 109 | 0x00000013 => {:ms_const => 'PRODUCT_HOME_SERVER', :name => 'Windows Storage Server 2008 R2 Essentials'}, 110 | 0x00000009 => {:ms_const => 'PRODUCT_SMALLBUSINESS_SERVER', :name => 'Windows Small Business Server'}, 111 | 0x00000038 => {:ms_const => 'PRODUCT_SOLUTION_EMBEDDEDSERVER', :name => 'Windows MultiPoint Server'}, 112 | 0x00000007 => {:ms_const => 'PRODUCT_STANDARD_SERVER', :name => 'Server Standard (full installation)'}, 113 | 0x0000000D => {:ms_const => 'PRODUCT_STANDARD_SERVER_CORE', :name => 'Server Standard (core installation)'}, 114 | 0x00000028 => {:ms_const => 'PRODUCT_STANDARD_SERVER_CORE_V', :name => 'Server Standard without Hyper-V (core installation)'}, 115 | 0x00000024 => {:ms_const => 'PRODUCT_STANDARD_SERVER_V', :name => 'Server Standard without Hyper-V (full installation)'}, 116 | 0x0000000B => {:ms_const => 'PRODUCT_STARTER', :name => 'Starter'}, 117 | 0x00000042 => {:ms_const => 'PRODUCT_STARTER_E', :name => 'Not supported'}, 118 | 0x0000002F => {:ms_const => 'PRODUCT_STARTER_N', :name => 'Starter N'}, 119 | 0x00000017 => {:ms_const => 'PRODUCT_STORAGE_ENTERPRISE_SERVER', :name => 'Storage Server Enterprise'}, 120 | 0x00000014 => {:ms_const => 'PRODUCT_STORAGE_EXPRESS_SERVER', :name => 'Storage Server Express'}, 121 | 0x00000015 => {:ms_const => 'PRODUCT_STORAGE_STANDARD_SERVER', :name => 'Storage Server Standard'}, 122 | 0x00000016 => {:ms_const => 'PRODUCT_STORAGE_WORKGROUP_SERVER', :name => 'Storage Server Workgroup'}, 123 | 0x00000000 => {:ms_const => 'PRODUCT_UNDEFINED', :name => 'An unknown product'}, 124 | 0x00000001 => {:ms_const => 'PRODUCT_ULTIMATE', :name => 'Ultimate'}, 125 | 0x00000047 => {:ms_const => 'PRODUCT_ULTIMATE_E', :name => 'Not supported'}, 126 | 0x0000001C => {:ms_const => 'PRODUCT_ULTIMATE_N', :name => 'Ultimate N'}, 127 | 0x00000011 => {:ms_const => 'PRODUCT_WEB_SERVER', :name => 'Web Server (full installation)'}, 128 | 0x0000001D => {:ms_const => 'PRODUCT_WEB_SERVER_CORE', :name => 'Web Server (core installation)'} 129 | } 130 | 131 | attr_reader :major_version, :minor_version, :build_number, :service_pack_major_version, :service_pack_minor_version 132 | attr_reader :version, :product_type, :product_suite, :sku 133 | 134 | def initialize 135 | unless RUBY_PLATFORM =~ /mswin|mingw32|windows/ 136 | raise NotImplementedError, 'only valid on Windows platform' 137 | end 138 | @version, @product_type, @product_suite, @sku, @service_pack_major_version, @service_pack_minor_version = get_os_info 139 | @major_version, @minor_version, @build_number = version.split('.').map{|v| v.to_i } 140 | end 141 | 142 | WIN_VERSIONS = { 143 | "Windows 7" => {:major => 6, :minor => 1, :callable => lambda{ @product_type == VER_NT_WORKSTATION }}, 144 | "Windows Server 2008 R2" => {:major => 6, :minor => 1, :callable => lambda{ @product_type != VER_NT_WORKSTATION }}, 145 | "Windows Server 2008" => {:major => 6, :minor => 0, :callable => lambda{ @product_type != VER_NT_WORKSTATION }}, 146 | "Windows Vista" => {:major => 6, :minor => 0, :callable => lambda{ @product_type == VER_NT_WORKSTATION }}, 147 | "Windows Server 2003 R2" => {:major => 5, :minor => 2, :callable => lambda{ Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(SM_SERVERR2) != 0 }}, 148 | "Windows Home Server" => {:major => 5, :minor => 2, :callable => lambda{ (@product_suite & VER_SUITE_WH_SERVER) == VER_SUITE_WH_SERVER }}, 149 | "Windows Server 2003" => {:major => 5, :minor => 2, :callable => lambda{ Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(SM_SERVERR2) == 0 }}, 150 | "Windows XP" => {:major => 5, :minor => 1}, 151 | "Windows 2000" => {:major => 5, :minor => 0} 152 | } 153 | 154 | marketing_names = Array.new 155 | 156 | # General Windows checks 157 | WIN_VERSIONS.each do |k,v| 158 | method_name = "#{k.gsub(/\s/, '_').downcase}?" 159 | define_method(method_name) do 160 | (@major_version == v[:major]) && 161 | (@minor_version == v[:minor]) && 162 | (v[:callable] ? v[:callable].call : true) 163 | end 164 | marketing_names << [k, method_name] 165 | end 166 | 167 | define_method(:marketing_name) do 168 | marketing_names.each do |mn| 169 | break mn[0] if self.send(mn[1]) 170 | end 171 | end 172 | 173 | # Server Type checks 174 | %w{ core full datacenter }.each do |m| 175 | define_method("server_#{m}?") do 176 | if @sku 177 | !(SKU[@sku][:name] =~ /#{m}/i).nil? 178 | else 179 | false 180 | end 181 | end 182 | end 183 | 184 | private 185 | # Win32API call to GetSystemMetrics(SM_SERVERR2) 186 | # returns: The build number if the system is Windows Server 2003 R2; otherwise, 0. 187 | def sm_serverr2 188 | @sm_serverr2 ||= Win32API.new('user32', 'GetSystemMetrics', 'I', 'I').call(SM_SERVERR2) 189 | end 190 | 191 | # query WMI Win32_OperatingSystem for required OS info 192 | def get_os_info 193 | cols = %w{ Version ProductType OSProductSuite OperatingSystemSKU ServicePackMajorVersion ServicePackMinorVersion } 194 | os_info = WMI::Win32_OperatingSystem.find(:first) 195 | cols.map do |c| 196 | begin 197 | os_info.send(c) 198 | rescue # OperatingSystemSKU doesn't exist in all versions of Windows 199 | nil 200 | end 201 | end 202 | end 203 | end 204 | end 205 | -------------------------------------------------------------------------------- /definitions/windows-2008r2-standard/Autounattend.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 1 15 | Primary 16 | 20000 17 | 18 | 19 | 20 | 21 | 22 | false 23 | NTFS 24 | C 25 | 1 26 | 1 27 | 28 | 29 | 30 | 31 | 0 32 | true 33 | 34 | 35 | OnError 36 | 37 | 38 | 39 | 40 | YC6KT-GKW9T-YTKYR-T4X34-R7VHC 41 | Never 42 | 43 | 44 | true 45 | Vagrant Fullname 46 | Vagrant Inc 47 | 48 | 49 | 50 | 51 | 52 | 0 53 | 1 54 | 55 | OnError 56 | false 57 | 58 | 59 | /IMAGE/NAME 60 | Windows Server 2008 R2 SERVERSTANDARD 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | en-US 71 | 72 | en-US 73 | en-US 74 | en-US 75 | en-US 76 | en-US 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | vagrant 86 | true</PlainText> 87 | </AdministratorPassword> 88 | <LocalAccounts> 89 | <LocalAccount wcm:action="add"> 90 | <Password> 91 | <Value>vagrant</Value> 92 | <PlainText>true</PlainText> 93 | </Password> 94 | <Description>Vagrant User</Description> 95 | <DisplayName>vagrant</DisplayName> 96 | <Group>administrators</Group> 97 | <Name>vagrant</Name> 98 | </LocalAccount> 99 | </LocalAccounts> 100 | </UserAccounts> 101 | <OOBE> 102 | <HideEULAPage>true</HideEULAPage> 103 | <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> 104 | <NetworkLocation>Home</NetworkLocation> 105 | </OOBE> 106 | <AutoLogon> 107 | <Password> 108 | <Value>vagrant</Value> 109 | <PlainText>true</PlainText> 110 | </Password> 111 | <Username>administrator</Username> 112 | <Enabled>true</Enabled> 113 | </AutoLogon> 114 | <FirstLogonCommands> 115 | <!-- <SynchronousCommand wcm:action="add"> --> 116 | <!-- <CommandLine>cmd.exe /c a:install-cygwin-sshd.bat</CommandLine> --> 117 | <!-- <Description>Install Cygwin SSH</Description> --> 118 | <!-- <Order>1</Order> --> 119 | <!-- <RequiresUserInput>true</RequiresUserInput> --> 120 | <!-- </SynchronousCommand> --> 121 | <!-- <SynchronousCommand wcm:action="add"> --> 122 | <!-- <CommandLine>cmd.exe /c a:install-winrm.bat</CommandLine> --> 123 | <!-- <Description>Install Win RM</Description> --> 124 | <!-- <Order>2</Order> --> 125 | <!-- <RequiresUserInput>true</RequiresUserInput> --> 126 | <!-- </SynchronousCommand> --> 127 | <SynchronousCommand wcm:action="add"> 128 | <CommandLine>cmd.exe /c winrm quickconfig -q</CommandLine> 129 | <Description>winrm quickconfig -q</Description> 130 | <Order>1</Order> 131 | <RequiresUserInput>true</RequiresUserInput> 132 | </SynchronousCommand> 133 | <SynchronousCommand wcm:action="add"> 134 | <CommandLine>cmd.exe /c winrm quickconfig -transport:http</CommandLine> 135 | <Description>winrm quickconfig -transport:http</Description> 136 | <Order>2</Order> 137 | <RequiresUserInput>true</RequiresUserInput> 138 | </SynchronousCommand> 139 | <SynchronousCommand wcm:action="add"> 140 | <CommandLine>cmd.exe /c winrm set winrm/config @{MaxTimeoutms="1800000"}</CommandLine> 141 | <Description>Win RM MaxTimoutms</Description> 142 | <Order>3</Order> 143 | <RequiresUserInput>true</RequiresUserInput> 144 | </SynchronousCommand> 145 | <SynchronousCommand wcm:action="add"> 146 | <CommandLine>cmd.exe /c winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}</CommandLine> 147 | <Description>Win RM MaxMemoryPerShellMB</Description> 148 | <Order>4</Order> 149 | <RequiresUserInput>true</RequiresUserInput> 150 | </SynchronousCommand> 151 | <SynchronousCommand wcm:action="add"> 152 | <CommandLine>cmd.exe /c winrm set winrm/config/service @{AllowUnencrypted="true"}</CommandLine> 153 | <Description>Win RM AllowUnencrypted</Description> 154 | <Order>5</Order> 155 | <RequiresUserInput>true</RequiresUserInput> 156 | </SynchronousCommand> 157 | <SynchronousCommand wcm:action="add"> 158 | <CommandLine>cmd.exe /c winrm set winrm/config/service/auth @{Basic="true"}</CommandLine> 159 | <Description>Win RM auth Basic</Description> 160 | <Order>6</Order> 161 | <RequiresUserInput>true</RequiresUserInput> 162 | </SynchronousCommand> 163 | <SynchronousCommand wcm:action="add"> 164 | <CommandLine>cmd.exe /c winrm set winrm/config/client/auth @{Basic="true"}</CommandLine> 165 | <Description>Win RM auth Basic</Description> 166 | <Order>7</Order> 167 | <RequiresUserInput>true</RequiresUserInput> 168 | </SynchronousCommand> 169 | <SynchronousCommand wcm:action="add"> 170 | <CommandLine>cmd.exe /c winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port="5985"} </CommandLine> 171 | <Description>Win RM listener Address/Port</Description> 172 | <Order>8</Order> 173 | <RequiresUserInput>true</RequiresUserInput> 174 | </SynchronousCommand> 175 | <SynchronousCommand wcm:action="add"> 176 | <CommandLine>cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes </CommandLine> 177 | <Description>Win RM adv firewall enable</Description> 178 | <Order>9</Order> 179 | <RequiresUserInput>true</RequiresUserInput> 180 | </SynchronousCommand> 181 | <SynchronousCommand wcm:action="add"> 182 | <CommandLine>cmd.exe /c netsh firewall add portopening TCP 5985 "Port 5985" </CommandLine> 183 | <Description>Win RM port open</Description> 184 | <Order>10</Order> 185 | <RequiresUserInput>true</RequiresUserInput> 186 | </SynchronousCommand> 187 | <SynchronousCommand wcm:action="add"> 188 | <CommandLine>cmd.exe /c net stop winrm </CommandLine> 189 | <Description>Stop Win RM Service </Description> 190 | <Order>11</Order> 191 | <RequiresUserInput>true</RequiresUserInput> 192 | </SynchronousCommand> 193 | <SynchronousCommand wcm:action="add"> 194 | <CommandLine>cmd.exe /c sc config winrm start= auto</CommandLine> 195 | <Description>Win RM Autostart</Description> 196 | <Order>12</Order> 197 | <RequiresUserInput>true</RequiresUserInput> 198 | </SynchronousCommand> 199 | <SynchronousCommand wcm:action="add"> 200 | <CommandLine>cmd.exe /c net start winrm </CommandLine> 201 | <Description>Start Win RM Service</Description> 202 | <Order>13</Order> 203 | <RequiresUserInput>true</RequiresUserInput> 204 | </SynchronousCommand> 205 | <SynchronousCommand wcm:action="add"> 206 | <CommandLine>powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> 207 | <Description>Start Win RM Service</Description> 208 | <Order>14</Order> 209 | <RequiresUserInput>true</RequiresUserInput> 210 | </SynchronousCommand> 211 | </FirstLogonCommands> 212 | <ShowWindowsLive>false</ShowWindowsLive> 213 | </component> 214 | </settings> 215 | <settings pass="specialize"> 216 | <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" > 217 | <OEMInformation> 218 | <HelpCustomized>false</HelpCustomized> 219 | </OEMInformation> 220 | <!-- Rename computer here. --> 221 | <ComputerName>vagrant-2008R2</ComputerName> 222 | <TimeZone>Pacific Standard Time</TimeZone> 223 | <RegisteredOwner></RegisteredOwner> 224 | </component> 225 | <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 226 | <SkipAutoActivation>true</SkipAutoActivation> 227 | </component> 228 | </settings> 229 | <cpi:offlineImage cpi:source="catalog:d:/sources/install_windows server 2008 r2 serverdatacenter.clg" xmlns:cpi="urn:schemas-microsoft-com:cpi" /> 230 | </unattend> 231 | -------------------------------------------------------------------------------- /definitions/windows-7-enterprise/Autounattend.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="utf-8"?> 2 | <unattend xmlns="urn:schemas-microsoft-com:unattend"> 3 | <servicing></servicing> 4 | <settings pass="windowsPE"> 5 | <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 6 | <DiskConfiguration> 7 | <Disk wcm:action="add"> 8 | <CreatePartitions> 9 | <CreatePartition wcm:action="add"> 10 | <Order>1</Order> 11 | <Type>Primary</Type> 12 | <Size>20000</Size> 13 | </CreatePartition> 14 | </CreatePartitions> 15 | <ModifyPartitions> 16 | <ModifyPartition wcm:action="add"> 17 | <Extend>false</Extend> 18 | <Format>NTFS</Format> 19 | <Letter>C</Letter> 20 | <Order>1</Order> 21 | <PartitionID>1</PartitionID> 22 | <Label>Windows 7 Enterprise</Label> 23 | </ModifyPartition> 24 | </ModifyPartitions> 25 | <DiskID>0</DiskID> 26 | <WillWipeDisk>true</WillWipeDisk> 27 | </Disk> 28 | <WillShowUI>OnError</WillShowUI> 29 | </DiskConfiguration> 30 | <UserData> 31 | <ProductKey> 32 | <WillShowUI>Never</WillShowUI> 33 | </ProductKey> 34 | <AcceptEula>true</AcceptEula> 35 | <FullName>Vagrant Fullname</FullName> 36 | <Organization>Vagrant Inc</Organization> 37 | </UserData> 38 | <ImageInstall> 39 | <OSImage> 40 | <InstallTo> 41 | <DiskID>0</DiskID> 42 | <PartitionID>1</PartitionID> 43 | </InstallTo> 44 | <WillShowUI>OnError</WillShowUI> 45 | <InstallToAvailablePartition>false</InstallToAvailablePartition> 46 | <InstallFrom> 47 | <MetaData wcm:action="add"> 48 | <Key>/IMAGE/NAME</Key> 49 | <Value>Windows 7 ENTERPRISE</Value> 50 | </MetaData> 51 | </InstallFrom> 52 | </OSImage> 53 | </ImageInstall> 54 | </component> 55 | <component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 56 | <SetupUILanguage> 57 | <UILanguage>en-US</UILanguage> 58 | </SetupUILanguage> 59 | <InputLocale>en-US</InputLocale> 60 | <SystemLocale>en-US</SystemLocale> 61 | <UILanguage>en-US</UILanguage> 62 | <UILanguageFallback>en-US</UILanguageFallback> 63 | <UserLocale>en-US</UserLocale> 64 | </component> 65 | </settings> 66 | <settings pass="oobeSystem"> 67 | <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 68 | <UserAccounts> 69 | <AdministratorPassword> 70 | <Value>vagrant</Value> 71 | <PlainText>false</PlainText> 72 | </AdministratorPassword> 73 | <LocalAccounts> 74 | <LocalAccount wcm:action="add"> 75 | <Password> 76 | <Value>vagrant</Value> 77 | <PlainText>true</PlainText> 78 | </Password> 79 | <Description>Vagrant User</Description> 80 | <DisplayName>vagrant</DisplayName> 81 | <Group>administrators</Group> 82 | <Name>vagrant</Name> 83 | </LocalAccount> 84 | </LocalAccounts> 85 | </UserAccounts> 86 | <OOBE> 87 | <HideEULAPage>true</HideEULAPage> 88 | <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> 89 | <NetworkLocation>Work</NetworkLocation> 90 | <ProtectYourPC>3</ProtectYourPC> 91 | </OOBE> 92 | <AutoLogon> 93 | <Password> 94 | <Value>vagrant</Value> 95 | <PlainText>true</PlainText> 96 | </Password> 97 | <Username>vagrant</Username> 98 | <Enabled>true</Enabled> 99 | </AutoLogon> 100 | <FirstLogonCommands> 101 | <!-- <SynchronousCommand wcm:action="add"> --> 102 | <!-- <CommandLine>cmd.exe /c a:install-cygwin-sshd.bat</CommandLine> --> 103 | <!-- <Description>Install Cygwin SSH</Description> --> 104 | <!-- <Order>1</Order> --> 105 | <!-- <RequiresUserInput>true</RequiresUserInput> --> 106 | <!-- </SynchronousCommand> --> 107 | <!-- <SynchronousCommand wcm:action="add"> --> 108 | <!-- <CommandLine>cmd.exe /c a:install-vbox-guest.bat</CommandLine> --> 109 | <!-- <Description>Install Win RM</Description> --> 110 | <!-- <Order>1</Order> --> 111 | <!-- <RequiresUserInput>true</RequiresUserInput> --> 112 | <!-- </SynchronousCommand> --> 113 | <SynchronousCommand wcm:action="add"> 114 | <CommandLine>cmd.exe /c winrm quickconfig -q</CommandLine> 115 | <Description>winrm quickconfig -q</Description> 116 | <Order>1</Order> 117 | <RequiresUserInput>true</RequiresUserInput> 118 | </SynchronousCommand> 119 | <SynchronousCommand wcm:action="add"> 120 | <CommandLine>cmd.exe /c winrm quickconfig -transport:http</CommandLine> 121 | <Description>winrm quickconfig -transport:http</Description> 122 | <Order>2</Order> 123 | <RequiresUserInput>true</RequiresUserInput> 124 | </SynchronousCommand> 125 | <SynchronousCommand wcm:action="add"> 126 | <CommandLine>cmd.exe /c winrm set winrm/config @{MaxTimeoutms="1800000"}</CommandLine> 127 | <Description>Win RM MaxTimoutms</Description> 128 | <Order>3</Order> 129 | <RequiresUserInput>true</RequiresUserInput> 130 | </SynchronousCommand> 131 | <SynchronousCommand wcm:action="add"> 132 | <CommandLine>cmd.exe /c winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}</CommandLine> 133 | <Description>Win RM MaxMemoryPerShellMB</Description> 134 | <Order>4</Order> 135 | <RequiresUserInput>true</RequiresUserInput> 136 | </SynchronousCommand> 137 | <SynchronousCommand wcm:action="add"> 138 | <CommandLine>cmd.exe /c winrm set winrm/config/service @{AllowUnencrypted="true"}</CommandLine> 139 | <Description>Win RM AllowUnencrypted</Description> 140 | <Order>5</Order> 141 | <RequiresUserInput>true</RequiresUserInput> 142 | </SynchronousCommand> 143 | <SynchronousCommand wcm:action="add"> 144 | <CommandLine>cmd.exe /c winrm set winrm/config/service/auth @{Basic="true"}</CommandLine> 145 | <Description>Win RM auth Basic</Description> 146 | <Order>6</Order> 147 | <RequiresUserInput>true</RequiresUserInput> 148 | </SynchronousCommand> 149 | <SynchronousCommand wcm:action="add"> 150 | <CommandLine>cmd.exe /c winrm set winrm/config/client/auth @{Basic="true"}</CommandLine> 151 | <Description>Win RM auth Basic</Description> 152 | <Order>7</Order> 153 | <RequiresUserInput>true</RequiresUserInput> 154 | </SynchronousCommand> 155 | <SynchronousCommand wcm:action="add"> 156 | <CommandLine>cmd.exe /c winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port="5985"} </CommandLine> 157 | <Description>Win RM listener Address/Port</Description> 158 | <Order>8</Order> 159 | <RequiresUserInput>true</RequiresUserInput> 160 | </SynchronousCommand> 161 | <SynchronousCommand wcm:action="add"> 162 | <CommandLine>cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes </CommandLine> 163 | <Description>Win RM adv firewall enable</Description> 164 | <Order>9</Order> 165 | <RequiresUserInput>true</RequiresUserInput> 166 | </SynchronousCommand> 167 | <SynchronousCommand wcm:action="add"> 168 | <CommandLine>cmd.exe /c netsh firewall add portopening TCP 5985 "Port 5985" </CommandLine> 169 | <Description>Win RM port open</Description> 170 | <Order>10</Order> 171 | <RequiresUserInput>true</RequiresUserInput> 172 | </SynchronousCommand> 173 | <SynchronousCommand wcm:action="add"> 174 | <CommandLine>cmd.exe /c net stop winrm </CommandLine> 175 | <Description>Stop Win RM Service </Description> 176 | <Order>11</Order> 177 | <RequiresUserInput>true</RequiresUserInput> 178 | </SynchronousCommand> 179 | <SynchronousCommand wcm:action="add"> 180 | <CommandLine>cmd.exe /c sc config winrm start= auto</CommandLine> 181 | <Description>Win RM Autostart</Description> 182 | <Order>12</Order> 183 | <RequiresUserInput>true</RequiresUserInput> 184 | </SynchronousCommand> 185 | <SynchronousCommand wcm:action="add"> 186 | <CommandLine>cmd.exe /c net start winrm </CommandLine> 187 | <Description>Start Win RM Service</Description> 188 | <Order>13</Order> 189 | <RequiresUserInput>true</RequiresUserInput> 190 | </SynchronousCommand> 191 | <SynchronousCommand wcm:action="add"> 192 | <CommandLine>powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> 193 | <Description>Start Win RM Service</Description> 194 | <Order>14</Order> 195 | <RequiresUserInput>true</RequiresUserInput> 196 | </SynchronousCommand> 197 | </FirstLogonCommands> 198 | <ShowWindowsLive>false</ShowWindowsLive> 199 | </component> 200 | </settings> 201 | <settings pass="specialize"> 202 | <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> 203 | <OEMInformation> 204 | <HelpCustomized>false</HelpCustomized> 205 | </OEMInformation> 206 | <!-- Rename computer here. --> 207 | <ComputerName>vagrant-win7ent</ComputerName> 208 | <TimeZone>Pacific Standard Time</TimeZone> 209 | <RegisteredOwner>Vagrant</RegisteredOwner> 210 | <ShowWindowsLive>false</ShowWindowsLive> 211 | </component> 212 | <component name="Microsoft-Windows-Security-SPP-UX" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 213 | <SkipAutoActivation>true</SkipAutoActivation> 214 | </component> 215 | <component name="Security-Malware-Windows-Defender" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 216 | <DisableAntiSpyware>true</DisableAntiSpyware> 217 | </component> 218 | <component name="Microsoft-Windows-SystemRestore-Main" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 219 | <DisableSR>1</DisableSR> 220 | </component> 221 | </settings> 222 | <settings pass="generalize"> 223 | <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 224 | <SkipRearm>1</SkipRearm> 225 | </component> 226 | </settings> 227 | <settings pass="offlineServicing"> 228 | <component name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 229 | <EnableLUA>false</EnableLUA> 230 | </component> 231 | </settings> 232 | <cpi:offlineImage cpi:source="catalog:d:/sources/install_windows 7 enterprise.clg" xmlns:cpi="urn:schemas-microsoft-com:cpi" /> 233 | </unattend> 234 | -------------------------------------------------------------------------------- /cookbooks/windows/metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "windows", 3 | "description": "Provides a set of useful Windows-specific primitives.", 4 | "long_description": "Description\n===========\n\nProvides a set of Windows-specific primitives (Chef resources) meant to aid in the creation of cookbooks/recipes targeting the Windows platform.\n\nRequirements\n============\n\nVersion 1.3.0+ of this cookbook requires Chef 0.10.10.\n\nPlatform\n--------\n\n* Windows XP\n* Windows Vista\n* Windows Server 2003 R2\n* Windows 7\n* Windows Server 2008 (R1, R2)\n\nCookbooks\n---------\n\n* chef_handler (`windows::reboot_handler` leverages the chef_handler LWRP)\n\nAttributes\n==========\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\nResource/Provider\n=================\n\nwindows\\_auto\\_run\n------------------\n\n### Actions\n\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\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\n\n # Run BGInfo at login\n windows_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\n end\n\n\nwindows\\_batch\n--------------\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\n- :run: run the batch file\n\n### Attribute Parameters\n\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\n windows_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\n end\n\n windows_batch \"echo some env vars\" do\n code <<-EOH\n echo %TEMP%\n echo %SYSTEMDRIVE%\n echo %PATH%\n echo %WINDIR%\n EOH\n end\n\nwindows\\_feature\n----------------\n\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(v=vs.85).aspx) and [Servermanagercmd](http://technet.microsoft.com/en-us/library/ee344834(WS.10).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 dism /online /Get-Features\n servermanagercmd -query\n\n### Actions\n\n- :install: install a Windows role/feature\n- :remove: remove a Windows role/feature\n\n### Attribute Parameters\n\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\n### Providers\n\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\n\n # enable the node as a DHCP Server\n windows_feature \"DHCPServer\" do\n action :install\n end\n\n # enable TFTP\n windows_feature \"TFTP\" do\n action :install\n end\n\n # disable Telnet client/server\n %w{ TelnetServer TelnetClient }.each do |feature|\n windows_feature feature do\n action :remove\n end\n end\n\nwindows\\_package\n----------------\n\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\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\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\n### Examples\n\n # install PuTTY (InnoSetup installer)\n windows_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\n end\n\n # install 7-Zip (MSI installer)\n windows_package \"7-Zip 9.20 (x64 edition)\" do\n source \"http://downloads.sourceforge.net/sevenzip/7z920-x64.msi\"\n action :install\n end\n\n # install Notepad++ (Y U No Emacs?) using a local installer\n windows_package \"Notepad++\" do\n source \"c:/installation_files/npp.5.9.2.Installer.exe\"\n action :install\n end\n\n # install VLC for that Xvid (NSIS installer)\n windows_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\n end\n\n # install Firefox as custom installer and manually set the silent install flags\n windows_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\n end\n\n # Google Chrome FTW (MSI installer)\n windows_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\n end\n\n # remove Google Chrome (but why??)\n windows_package \"Google Chrome\" do\n action :remove\n end\n\n # remove 7-Zip\n windows_package \"7-Zip 9.20 (x64 edition)\" do\n action :remove\n end\n\n\nwindows\\_reboot\n---------------\n\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\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\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\n\n # if the package installs, schedule a reboot at end of chef run\n windows_reboot 60 do\n reason 'cause chef said so'\n action :nothing\n end\n windows_package 'some_package' do\n action :install\n notifies :request, 'windows_reboot[60]'\n end\n\n # cancel the previously requested reboot\n windows_reboot 60 do\n action :cancel\n end\n\nwindows\\_registry\n-----------------\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\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\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, currently only used for :binary to create `REG_BINARY` registry keys. Must be a symbol. See __Roadmap__ for future plans.\n\n### Examples\n\n # make the local windows proxy match the one set for Chef\n proxy = URI.parse(Chef::Config[:http_proxy])\n windows_registry 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings' do\n values 'ProxyEnable' => 1, 'ProxyServer' => \"#{proxy.host}:#{proxy.port}\", 'ProxyOverride' => '<local>'\n end\n\n # enable Remote Desktop and poke the firewall hole\n windows_registry 'HKLM\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server' do\n values 'FdenyTSConnections' => 0\n end\n\n # Delete an item from the registry\n windows_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\n end\n\n### Library Methods\n\n Registry.value_exists?('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run','BGINFO')\n Registry.key_exists?('HKLM\\SOFTWARE\\Microsoft')\n BgInfo = Registry.get_value('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run','BGINFO')\n\nwindows\\_path\n-------------\n\n### Actions\n\n- :add: Add an item to the system path\n- :remove: Remove an item from the system path\n\n### Attribute Parameters\n\n- :path: Name attribute. The name of the value to add to the system path\n\n### Examples\n\n #Add Sysinternals to the system path\n windows_path 'C:\\Sysinternals' do\n action :add\n end\n\n #Remove 7-Zip from the system path\n windows_path 'C:\\7-Zip' do\n action :remove\n end\n\n\nwindows\\_zipfile\n----------------\n\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\n- :unzip: unzip a compressed file\n\n### Attribute Parameters\n\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\n### Examples\n\n # unzip a remote zip file locally\n windows_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\")}\n end\n\n # unzip a local zipfile\n windows_zipfile \"c:/the_codez\" do\n source \"c:/foo/baz/the_codez.zip\"\n action :unzip\n end\n\n\nException/Report Handlers\n=========================\n\nWindowsRebootHandler\n--------------------\n\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\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\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 depends \"windows\"\n\ndefault\n-------\n\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\nreboot\\_handler\n--------------\n\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 % cat roles/base.rb\n name \"base\"\n description \"base role\"\n override_attributes(\n \"windows\" => {\n \"allow_pending_reboots\" => false\n }\n )\n\nThis will still allow a reboot to be explicitly requested via the `windows_reboot` LWRP.\n\nLicense and Author\n==================\n\nAuthor:: Seth Chisamore (<schisamo@opscode.com>)\nAuthor:: Doug MacEachern (<dougm@vmware.com>)\nAuthor:: Paul Morton (<pmorton@biaprotect.com>)\n\nCopyright:: 2011, Opscode, Inc.\nCopyright:: 2010, VMware, Inc.\nCopyright:: 2011, Business Intelligence Associates, Inc\n\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", 5 | "maintainer": "Opscode, Inc.", 6 | "maintainer_email": "cookbooks@opscode.com", 7 | "license": "Apache 2.0", 8 | "platforms": { 9 | "windows": ">= 0.0.0" 10 | }, 11 | "dependencies": { 12 | "chef_handler": ">= 0.0.0" 13 | }, 14 | "recommendations": { 15 | }, 16 | "suggestions": { 17 | }, 18 | "conflicting": { 19 | }, 20 | "providing": { 21 | }, 22 | "replacing": { 23 | }, 24 | "attributes": { 25 | }, 26 | "groupings": { 27 | }, 28 | "recipes": { 29 | }, 30 | "version": "1.3.4" 31 | } -------------------------------------------------------------------------------- /cookbooks/windows/README.md: -------------------------------------------------------------------------------- 1 | Description 2 | =========== 3 | 4 | Provides a set of Windows-specific primitives (Chef resources) meant to aid in the creation of cookbooks/recipes targeting the Windows platform. 5 | 6 | Requirements 7 | ============ 8 | 9 | Version 1.3.0+ of this cookbook requires Chef 0.10.10. 10 | 11 | Platform 12 | -------- 13 | 14 | * Windows XP 15 | * Windows Vista 16 | * Windows Server 2003 R2 17 | * Windows 7 18 | * Windows Server 2008 (R1, R2) 19 | 20 | Cookbooks 21 | --------- 22 | 23 | * chef_handler (`windows::reboot_handler` leverages the chef_handler LWRP) 24 | 25 | Attributes 26 | ========== 27 | 28 | * `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. 29 | 30 | Resource/Provider 31 | ================= 32 | 33 | windows\_auto\_run 34 | ------------------ 35 | 36 | ### Actions 37 | 38 | - :create: Create an item to be run at login 39 | - :remove: Remove an item that was previously setup to run at login 40 | 41 | ### Attribute Parameters 42 | 43 | - :name: Name attribute. The name of the value to be stored in the registry 44 | - :program: The program to be run at login 45 | - :args: The arguments for the program 46 | 47 | ### Examples 48 | 49 | # Run BGInfo at login 50 | windows_auto_run 'BGINFO' do 51 | program "C:/Sysinternals/bginfo.exe" 52 | args "\"C:/Sysinternals/Config.bgi\" /NOLICPROMPT /TIMER:0" 53 | not_if { Registry.value_exists?(AUTO_RUN_KEY, 'BGINFO') } 54 | action :create 55 | end 56 | 57 | 58 | windows\_batch 59 | -------------- 60 | 61 | Execute 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. 62 | 63 | ### Actions 64 | 65 | - :run: run the batch file 66 | 67 | ### Attribute Parameters 68 | 69 | - command: name attribute. Name of the command to execute. 70 | - code: quoted string of code to execute. 71 | - creates: a file this command creates - if the file exists, the command will not be run. 72 | - cwd: current working directory to run the command from. 73 | - flags: command line flags to pass to the interpreter when invoking. 74 | - user: A user name or user ID that we should change to before running this command. 75 | - group: A group name or group ID that we should change to before running this command. 76 | 77 | ### Examples 78 | 79 | windows_batch "unzip_and_move_ruby" do 80 | code <<-EOH 81 | 7z.exe x #{Chef::Config[:file_cache_path]}/ruby-1.8.7-p352-i386-mingw32.7z -oC:\\source -r -y 82 | xcopy C:\\source\\ruby-1.8.7-p352-i386-mingw32 C:\\ruby /e /y 83 | EOH 84 | end 85 | 86 | windows_batch "echo some env vars" do 87 | code <<-EOH 88 | echo %TEMP% 89 | echo %SYSTEMDRIVE% 90 | echo %PATH% 91 | echo %WINDIR% 92 | EOH 93 | end 94 | 95 | windows\_feature 96 | ---------------- 97 | 98 | Windows 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'. 99 | 100 | This resource allows you to manage these 'features' in an unattended, idempotent way. 101 | 102 | There 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(v=vs.85).aspx) and [Servermanagercmd](http://technet.microsoft.com/en-us/library/ee344834(WS.10).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`. 103 | 104 | For 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: 105 | 106 | dism /online /Get-Features 107 | servermanagercmd -query 108 | 109 | ### Actions 110 | 111 | - :install: install a Windows role/feature 112 | - :remove: remove a Windows role/feature 113 | 114 | ### Attribute Parameters 115 | 116 | - 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). 117 | 118 | ### Providers 119 | 120 | - **Chef::Provider::WindowsFeature::DISM**: Uses Deployment Image Servicing and Management (DISM) to manage roles/features. 121 | - **Chef::Provider::WindowsFeature::ServerManagerCmd**: Uses Server Manager to manage roles/features. 122 | 123 | ### Examples 124 | 125 | # enable the node as a DHCP Server 126 | windows_feature "DHCPServer" do 127 | action :install 128 | end 129 | 130 | # enable TFTP 131 | windows_feature "TFTP" do 132 | action :install 133 | end 134 | 135 | # disable Telnet client/server 136 | %w{ TelnetServer TelnetClient }.each do |feature| 137 | windows_feature feature do 138 | action :remove 139 | end 140 | end 141 | 142 | windows\_package 143 | ---------------- 144 | 145 | Manage Windows application packages in an unattended, idempotent way. 146 | 147 | The following application installers are currently supported: 148 | 149 | * MSI packages 150 | * InstallShield 151 | * Wise InstallMaster 152 | * Inno Setup 153 | * Nullsoft Scriptable Install System 154 | 155 | If 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). 156 | 157 | __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: 158 | 159 | * `HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall` 160 | * `HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall` 161 | * `HKEY_LOCAL_MACHINE\Software\Wow6464Node\Microsoft\Windows\CurrentVersion\Uninstall` 162 | 163 | For maximum flexibility the `source` attribute supports both remote and local installation packages. 164 | 165 | ### Actions 166 | 167 | - :install: install a package 168 | - :remove: remove a package. The remove action is completely hit or miss as many application uninstallers do not support a full silent/quiet mode. 169 | 170 | ### Attribute Parameters 171 | 172 | - package_name: name attribute. The 'DisplayName' of the application installation package. 173 | - source: The source of the windows installer. This can either be a URI or a local path. 174 | - 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. 175 | - 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 176 | - options: Additional options to pass the underlying installation command 177 | - timeout: set a timeout for the package download (default 600 seconds) 178 | 179 | ### Examples 180 | 181 | # install PuTTY (InnoSetup installer) 182 | windows_package "PuTTY version 0.60" do 183 | source "http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.60-installer.exe" 184 | installer_type :inno 185 | action :install 186 | end 187 | 188 | # install 7-Zip (MSI installer) 189 | windows_package "7-Zip 9.20 (x64 edition)" do 190 | source "http://downloads.sourceforge.net/sevenzip/7z920-x64.msi" 191 | action :install 192 | end 193 | 194 | # install Notepad++ (Y U No Emacs?) using a local installer 195 | windows_package "Notepad++" do 196 | source "c:/installation_files/npp.5.9.2.Installer.exe" 197 | action :install 198 | end 199 | 200 | # install VLC for that Xvid (NSIS installer) 201 | windows_package "VLC media player 1.1.10" do 202 | source "http://superb-sea2.dl.sourceforge.net/project/vlc/1.1.10/win32/vlc-1.1.10-win32.exe" 203 | action :install 204 | end 205 | 206 | # install Firefox as custom installer and manually set the silent install flags 207 | windows_package "Mozilla Firefox 5.0 (x86 en-US)" do 208 | source "http://archive.mozilla.org/pub/mozilla.org/mozilla.org/firefox/releases/5.0/win32/en-US/Firefox%20Setup%205.0.exe" 209 | options "-ms" 210 | installer_type :custom 211 | action :install 212 | end 213 | 214 | # Google Chrome FTW (MSI installer) 215 | windows_package "Google Chrome" do 216 | 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" 217 | action :install 218 | end 219 | 220 | # remove Google Chrome (but why??) 221 | windows_package "Google Chrome" do 222 | action :remove 223 | end 224 | 225 | # remove 7-Zip 226 | windows_package "7-Zip 9.20 (x64 edition)" do 227 | action :remove 228 | end 229 | 230 | 231 | windows\_reboot 232 | --------------- 233 | 234 | Sets 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). 235 | 236 | ### Actions 237 | 238 | - :request: requests a reboot at completion of successful Cher run. requires `WindowsRebootHandler` to be registered as a report handler. 239 | - :cancel: remove reboot request from node.run_state. this will cancel *ALL* previously requested reboots as this is a binary state. 240 | 241 | ### Attribute Parameters 242 | 243 | - :timeout: Name attribute. timeout delay in seconds to wait before proceeding with the requested reboot. default is 60 seconds 244 | - :reason: comment on the reason for the reboot. default is 'Opscode Chef initiated reboot' 245 | 246 | ### Examples 247 | 248 | # if the package installs, schedule a reboot at end of chef run 249 | windows_reboot 60 do 250 | reason 'cause chef said so' 251 | action :nothing 252 | end 253 | windows_package 'some_package' do 254 | action :install 255 | notifies :request, 'windows_reboot[60]' 256 | end 257 | 258 | # cancel the previously requested reboot 259 | windows_reboot 60 do 260 | action :cancel 261 | end 262 | 263 | windows\_registry 264 | ----------------- 265 | 266 | Creates and modifies Windows registry keys. 267 | 268 | *Change in v1.3.0: The Win32 classes use `::Win32` to avoid namespace conflict with `Chef::Win32` (introduced in Chef 0.10.10).* 269 | 270 | ### Actions 271 | 272 | - :create: create a new registry key with the provided values. 273 | - :modify: modify an existing registry key with the provided values. 274 | - :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. 275 | - :remove: removes a value from an existing registry key 276 | 277 | ### Attribute Parameters 278 | 279 | - key_name: name attribute. The registry key to create/modify. 280 | - 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. 281 | - type: Type of key to create, currently only used for :binary to create `REG_BINARY` registry keys. Must be a symbol. See __Roadmap__ for future plans. 282 | 283 | ### Examples 284 | 285 | # make the local windows proxy match the one set for Chef 286 | proxy = URI.parse(Chef::Config[:http_proxy]) 287 | windows_registry 'HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings' do 288 | values 'ProxyEnable' => 1, 'ProxyServer' => "#{proxy.host}:#{proxy.port}", 'ProxyOverride' => '<local>' 289 | end 290 | 291 | # enable Remote Desktop and poke the firewall hole 292 | windows_registry 'HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server' do 293 | values 'FdenyTSConnections' => 0 294 | end 295 | 296 | # Delete an item from the registry 297 | windows_registry 'HKCU\Software\Test' do 298 | #Key is the name of the value that you want to delete the value is always empty 299 | values 'ValueToDelete' => '' 300 | action :remove 301 | end 302 | 303 | ### Library Methods 304 | 305 | Registry.value_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run','BGINFO') 306 | Registry.key_exists?('HKLM\SOFTWARE\Microsoft') 307 | BgInfo = Registry.get_value('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run','BGINFO') 308 | 309 | windows\_path 310 | ------------- 311 | 312 | ### Actions 313 | 314 | - :add: Add an item to the system path 315 | - :remove: Remove an item from the system path 316 | 317 | ### Attribute Parameters 318 | 319 | - :path: Name attribute. The name of the value to add to the system path 320 | 321 | ### Examples 322 | 323 | #Add Sysinternals to the system path 324 | windows_path 'C:\Sysinternals' do 325 | action :add 326 | end 327 | 328 | #Remove 7-Zip from the system path 329 | windows_path 'C:\7-Zip' do 330 | action :remove 331 | end 332 | 333 | 334 | windows\_zipfile 335 | ---------------- 336 | 337 | Most 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. 338 | 339 | ### Actions 340 | 341 | - :unzip: unzip a compressed file 342 | 343 | ### Attribute Parameters 344 | 345 | - path: name attribute. The path where files will be unzipped to. 346 | - source: The source of the zip file. This can either be a URI or a local path. 347 | - overwrite: force an overwrite of the files if the already exists. 348 | 349 | ### Examples 350 | 351 | # unzip a remote zip file locally 352 | windows_zipfile "c:/bin" do 353 | source "http://download.sysinternals.com/Files/SysinternalsSuite.zip" 354 | action :unzip 355 | not_if {::File.exists?("c:/bin/PsExec.exe")} 356 | end 357 | 358 | # unzip a local zipfile 359 | windows_zipfile "c:/the_codez" do 360 | source "c:/foo/baz/the_codez.zip" 361 | action :unzip 362 | end 363 | 364 | 365 | Exception/Report Handlers 366 | ========================= 367 | 368 | WindowsRebootHandler 369 | -------------------- 370 | 371 | 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. 372 | 373 | ## Initialization Arguments 374 | 375 | - `allow_pending_reboots`: indicator on whether the handler should act on a the Window's 'pending reboot' state. default is true 376 | - `timeout`: timeout delay in seconds to wait before proceeding with the reboot. default is 60 seconds 377 | - `reason`: comment on the reason for the reboot. default is 'Opscode Chef initiated reboot' 378 | 379 | Usage 380 | ===== 381 | 382 | Place 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. 383 | 384 | depends "windows" 385 | 386 | default 387 | ------- 388 | 389 | Convenience recipe that installs supporting gems for many of the resources/providers that ship with this cookbook. 390 | 391 | *Change in v1.3.0: Uses chef_gem instead of gem_package to ensure gem installation in Chef 0.10.10.* 392 | 393 | reboot\_handler 394 | -------------- 395 | 396 | Leverages 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: 397 | 398 | % cat roles/base.rb 399 | name "base" 400 | description "base role" 401 | override_attributes( 402 | "windows" => { 403 | "allow_pending_reboots" => false 404 | } 405 | ) 406 | 407 | This will still allow a reboot to be explicitly requested via the `windows_reboot` LWRP. 408 | 409 | License and Author 410 | ================== 411 | 412 | Author:: Seth Chisamore (<schisamo@opscode.com>) 413 | Author:: Doug MacEachern (<dougm@vmware.com>) 414 | Author:: Paul Morton (<pmorton@biaprotect.com>) 415 | 416 | Copyright:: 2011, Opscode, Inc. 417 | Copyright:: 2010, VMware, Inc. 418 | Copyright:: 2011, Business Intelligence Associates, Inc 419 | 420 | 421 | Licensed under the Apache License, Version 2.0 (the "License"); 422 | you may not use this file except in compliance with the License. 423 | You may obtain a copy of the License at 424 | 425 | http://www.apache.org/licenses/LICENSE-2.0 426 | 427 | Unless required by applicable law or agreed to in writing, software 428 | distributed under the License is distributed on an "AS IS" BASIS, 429 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 430 | See the License for the specific language governing permissions and 431 | limitations under the License. 432 | --------------------------------------------------------------------------------