Skip to content

Instantly share code, notes, and snippets.

@dennypc
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennypc/4460584835df2fca9c0a to your computer and use it in GitHub Desktop.
Save dennypc/4460584835df2fca9c0a to your computer and use it in GitHub Desktop.
Vagrantfile for Provisioning via DSC
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
# Global Variables
GUEST_PROJ_DIR = "C:\\vagrant\\"
GUEST_MODULE_DIR = GUEST_PROJ_DIR + "DSC\\Modules\\"
GUEST_MOF_DIR = GUEST_PROJ_DIR + "DSC\\MOF\\"
GUEST_WEBAPP_DIR = GUEST_PROJ_DIR + "MySite\\"
GUEST_HOSTNAME = "webserver01"
# Script to Load DSC Module Dependencies
# - Installs Third-Party modules via PowerShellGet
# - Installs the Project's Custom DSC Modules
$dscModDepScript = <<SCRIPT
Write-Host "Installing Third-Party DSC Modules"
Install-Module -Name xWebAdministration -Version 1.3.2.2
if (Test-Path($Args[0])) {
Write-Host "Installing Project DSC Modules"
Copy-Item ($Args[0]) -Destination (\$env:ProgramFiles + "\\WindowsPowerShell\\Modules\\") -Recurse -Container -Force
}
Get-DscResource
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ws2012e_r2_wmf5"
config.vm.communicator = "winrm"
config.vm.hostname = GUEST_HOSTNAME
config.vm.network "forwarded_port", host: 33389, guest: 3389
config.vm.network "forwarded_port", host: 8080, guest: 80
config.vm.network "forwarded_port", host: 4443, guest: 443
# Install DSC Module Dependencies
config.vm.provision "shell" do |s|
s.inline = $dscModDepScript
s.args = [GUEST_MODULE_DIR + "*"]
end
# Initialize DSC Configuration and Generate MOF file
config.vm.provision "shell" do |s|
s.path = "DSC/Config/MySiteConfig.ps1"
s.args = [GUEST_HOSTNAME, GUEST_MOF_DIR, GUEST_WEBAPP_DIR]
end
# Apply DSC Configuration
config.vm.provision "shell" do |s|
s.inline = "Start-DSCConfiguration -Path $Args[0] -Force -Wait -Verbose -Debug"
s.args = [GUEST_MOF_DIR + "MySite\\"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment