Last active
December 27, 2015 05:29
-
-
Save kardeiz/7273938 to your computer and use it in GitHub Desktop.
Chef Windows Server 2008 recipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DCINSTALL] | |
SafeModeAdminPassword=<%= @admin_password %> | |
RebootOnCompletion=Yes | |
ReplicaOrNewDomain=domain | |
NewDomain=forest | |
NewDomainDNSName=<%= @domain_name %> | |
ForestLevel=3 | |
DomainLevel=3 | |
InstallDNS=yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ServerHelper | |
extend ::Windows::Helper | |
class << self | |
def dism | |
@@dism ||= locate_sysnative_cmd("dism.exe") | |
end | |
def powershell | |
@@powershell ||= locate_sysnative_cmd('WindowsPowershell\v1.0\powershell.exe') | |
end | |
def feature_installed?(feature) | |
cmd = Mixlib::ShellOut.new("#{dism} /online /Get-Features", {:returns => [0,42,127]}).run_command | |
!!(cmd.stderr.empty? && (cmd.stdout =~ /^Feature Name : #{feature}.?$\n^State : Enabled.?$/i)) | |
end | |
end | |
end | |
windows_reboot 60 do | |
action :nothing | |
end | |
directory Chef::Config[:file_cache_path] | |
dcpromo_file = File.join(Chef::Config[:file_cache_path], 'dcpromo_unattend.txt') | |
cert_script = File.join(Chef::Config[:file_cache_path], 'setupca.vbs') | |
# Available from e.g. http://blogs.technet.com/b/pki/archive/2009/09/18/automated-ca-installs-using-vb-script-on-windows-server-2008-and-2008r2.aspx | |
template dcpromo_file do | |
source "dcpromo_unattend.txt.erb" | |
variables({ | |
:admin_password => '', | |
:domain_name => '' | |
}) | |
end | |
powershell "run_dcpromo" do | |
code "dcpromo /unattend:#{dcpromo_file}" | |
#notifies :request, 'windows_reboot[60]' | |
not_if { ServerHelper.feature_installed? 'DirectoryServices-DomainController' } | |
end | |
windows_feature 'DirectoryServices-DomainController' do | |
action :install | |
#notifies :request, 'windows_reboot[60]' | |
end | |
windows_feature 'CertificateServices' do | |
action :install | |
#notifies :request, 'windows_reboot[60]' | |
end | |
windows_feature 'CertificateServicesManagementTools' do | |
action :install | |
#notifies :request, 'windows_reboot[60]' | |
end | |
powershell "install_rds_server" do | |
code %Q{ | |
Import-Module Servermanager; Add-WindowsFeature RDS-RD-Server | |
}.strip | |
not_if %Q{ | |
#{ServerHelper.powershell} "Import-Module Servermanager; $check = get-windowsfeature -name RDS-RD-Server; if ($check.Installed -ne 'True') { exit 1 }" | |
}.strip | |
end | |
powershell "setupca" do | |
code %Q{ | |
cscript #{cert_script} /ie /sn SLLCA /sk 4096 /sp "RSA#Microsoft Software Key Storage Provider" /sa SHA256 | |
}.strip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment