├── .gitignore ├── .travis.yml ├── .vscode └── launch.json ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── appveyor.yml ├── development ├── reboot │ ├── Vagrantfile │ └── manifests │ │ ├── LCMConfig.ps1 │ │ └── Reboot.ps1 └── web │ ├── Vagrantfile │ ├── manifests │ ├── MyConfig.psd1 │ └── MyWebsite.ps1 │ ├── modules │ └── MyWebapp │ │ ├── DSCResources │ │ └── SimpleWebsite │ │ │ ├── SimpleWebsite.psd1 │ │ │ └── SimpleWebsite.schema.psm1 │ │ └── MyWebapp.psd1 │ └── website │ └── index.html ├── lib ├── vagrant-dsc.rb └── vagrant-dsc │ ├── config.rb │ ├── locales │ └── en.yml │ ├── plugin.rb │ ├── powershell │ └── configure_dsc.ps1 │ ├── provisioner.rb │ ├── templates │ └── runner.ps1.erb │ └── version.rb ├── spec ├── base.rb ├── provisioner │ ├── config_spec.rb │ └── provisioner_spec.rb └── spec_helper.rb └── vagrant-dsc.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | *.bundle 19 | *.so 20 | *.o 21 | *.a 22 | mkmf.log 23 | .vagrant 24 | .idea 25 | bin/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | before_install: 3 | - rvm @global do gem uninstall bundler --all --executables 4 | - gem uninstall bundler --all --executables 5 | - gem install bundler --version '1.12.5' 6 | rvm: 7 | - 2.2.3 8 | - ruby-head 9 | matrix: 10 | allow_failures: 11 | - rvm: ruby-head 12 | fast_finish: true 13 | env: 14 | matrix: 15 | - VAGRANT_VERSION=v1.8.5 16 | global: 17 | secure: d34dSoYsh9C9tCgAeKp3TIYdxPlrGh1j+x01Igg7Ku0rmmv0f1+NSZOcSpgbf5daXFk1i5mQrRcYjIVOclGAlCXM7IKWfDyefstmYl+2+Hjv4LGJHQNvBTz02MerfKlUef2HMAt3HJsNvwhqvIVrHetC6ZeSaFtupWqhuXWgREQ= 18 | script: bundle exec rake test:unit 19 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Launch Tests", 6 | "type": "Ruby", 7 | "request": "launch", 8 | "cwd": "${workspaceRoot}", 9 | "program": "${workspaceRoot}/bin/rake", 10 | "args": [ 11 | "spec" 12 | ] 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in vagrant-dsc.gemspec 4 | gemspec 5 | 6 | group :development do 7 | gem "vagrant", git: "https://github.com/mitchellh/vagrant.git" 8 | end 9 | 10 | group :plugins do 11 | gem "vagrant-dsc", path: "." 12 | end -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Matt Fellows 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vagrant DSC Plugin 2 | 3 | [![Build Status](https://travis-ci.org/mefellows/vagrant-dsc.svg)](https://travis-ci.org/mefellows/vagrant-dsc) 4 | [![Coverage Status](https://coveralls.io/repos/mefellows/vagrant-dsc/badge.png?branch=master)](https://coveralls.io/r/mefellows/vagrant-dsc?branch=master) 5 | [![Gem Version](https://badge.fury.io/rb/vagrant-dsc.svg)](http://badge.fury.io/rb/vagrant-dsc) 6 | 7 | [Desired State Configuration](https://msdn.microsoft.com/en-us/powershell/dsc/overview) provisioning plugin for Vagrant, enabling you to quickly configure & bootstrap a Windows Virtual Machine in a repeatable, reliable fashion - the Vagrant way. 8 | 9 | .NET Devs - no more excuses... 10 | 11 | > But it works on my machine!? 12 | 13 | ...is a thing of the past 14 | 15 | ## Features 16 | 17 | 1. Automated provisioning using [PowerShell DSC](https://msdn.microsoft.com/en-us/powershell/dsc/overview) 18 | 2. Install modules from the [Powershell Gallery](https://www.powershellgallery.com/) 19 | with PowerShellGet / PowerShell5 20 | 3. Windows development machine from zero to dev-ready < 5 minutes! 21 | 22 | ## Installation 23 | 24 | ```vagrant plugin install vagrant-dsc``` 25 | 26 | ## Usage 27 | 28 | In your Vagrantfile, add the following plugin and configure to your needs: 29 | 30 | ```ruby 31 | config.vm.provision "dsc" do |dsc| 32 | 33 | # The path relative to `dsc.manifests_path` pointing to the Configuration file 34 | dsc.configuration_file = "MyWebsite.ps1" 35 | 36 | # The Configuration Command to run. Assumed to be the same as the `dsc.configuration_file` 37 | # (sans extension) if not provided. 38 | dsc.configuration_name = "MyWebsite" 39 | 40 | # Commandline arguments to the Configuration run 41 | # Set of Parameters to pass to the DSC Configuration. 42 | # 43 | # To pass in flags, simply set the value to `nil` 44 | dsc.configuration_params = {"-MachineName" => "localhost", "-EnableDebug" => nil} 45 | 46 | # A path relative to the Vagrantfile pointing to a Configuration Data file. 47 | # 48 | # See https://technet.microsoft.com/en-us/library/dn249925.aspx for details 49 | # on how to parameterise your Configuration files. 50 | dsc.configuration_data_file = "manifests/MyConfig.psd1" 51 | 52 | # Relative path to a folder containing a pre-generated MOF file. 53 | # 54 | # Path is relative to the folder containing the Vagrantfile. 55 | # When set, `configuration_name`, `configuration_data_file_path`, 56 | # `configuration_file_path`, `configuration_data_file` and 57 | # `manifests_path` are ignored. 58 | dsc.mof_path = "mof_output" 59 | 60 | # Relative path to the folder containing the root Configuration manifest file. 61 | # Defaults to 'manifests'. 62 | # 63 | # Path is relative to the folder containing the Vagrantfile. 64 | dsc.manifests_path = "manifests" 65 | 66 | # Set of module paths relative to the Vagrantfile dir. 67 | # 68 | # These paths are added to the DSC Configuration running 69 | # environment to enable local modules to be addressed. 70 | dsc.module_path = ["manifests", "modules"] 71 | 72 | # Set of modules to install from the PowerShell Gallery 73 | # (https://www.powershellgallery.com/). 74 | # 75 | # Requires PowerShell 5 or PowerShellGet installed on guest machine. 76 | # 77 | # These modules are downloaded and installed when provisioning, 78 | # if a module is already installed it is a no-op. 79 | dsc.module_install = ["xNetworking", "xComputerManagement"] 80 | 81 | # The type of synced folders to use when sharing the data 82 | # required for the provisioner to work properly. 83 | # 84 | # By default this will use the default synced folder type. 85 | # For example, you can set this to "nfs" to use NFS synced folders. 86 | dsc.synced_folder_type = "nfs" 87 | 88 | # Whether to abort the vagrant run if DSC fails. 89 | # 90 | # By default, this is false. 91 | dsc.abort_on_dsc_failure = true 92 | 93 | # Temporary working directory on the guest machine. 94 | dsc.temp_dir = "/tmp/vagrant-dsc" 95 | end 96 | ``` 97 | 98 | ### Specifying a MOF file 99 | 100 | If `mof_path` is set then `configuration_name`, `configuration_data_file_path`, `configuration_file_path`, `configuration_data_file` and `manifests_path` are all not required, and will be ignored. Once you have a MOF file, you have everything you need (except possibly any paths to modules i.e. `module_paths`) to execute DSC 101 | 102 | If you don't know what a MOF file is, you probably don't need it and can safely ignore this setting. 103 | Vagrant DSC will create and manage it for you automatically. 104 | 105 | ## Example 106 | 107 | There is a [sample](https://github.com/mefellows/vagrant-dsc/tree/master/development/web) 108 | Vagrant setup used for development of this plugin. This is a great real-life example 109 | to get you on your way. 110 | 111 | ## Creating Windows Vagrant boxes 112 | 113 | Look at some example Packer templates [here](https://github.com/mefellows/packer-windows-templates/). 114 | 115 | ## Roadmap 116 | 117 | * Support DSC Pull Server provisioning 118 | * Test (dry-run) a DSC Configuration Run with 'vagrant vagrant-dsc test' 119 | * Support for non-Windows environments 120 | 121 | ### Supported Environments 122 | 123 | Currently the plugin only supports modern Windows environments with DSC installed (Windows 8.1+, Windows Server 2012 R2+ are safe bets). 124 | The plugin works on older platforms that have a later version of .NET (4.5) and the WMF 4.0 installed. 125 | 126 | As a general guide, configuring your Windows Server 127 | 128 | From the [DSC Book](https://www.penflip.com/powershellorg/the-dsc-book): 129 | 130 | > **DSC Overview and Requirements** 131 | > Desired State Configuration (DSC) was first introduced as part of Windows Management Framework (WMF) 4.0, which is preinstalled in Windows 8.1 and Windows Server 2012 R2, and is available for Windows 7, Windows Server 2008 R2, and Windows Server 2012. Because Windows 8.1 is a free upgrade to Windows 8, WMF 4 is not available for Windows 8. 132 | > You must have WMF 4.0 on a computer if you plan to author configurations there. You must also have WMF 4.0 on any computer you plan to manage via DSC. Every computer involved in the entire DSC conversation must have WMF 4.0 installed. Period. Check $PSVersionTable in PowerShell if you’re not sure what version is installed on a computer. 133 | > On Windows 8.1 and Windows Server 2012 R2, make certain that KB2883200 is installed or DSC will not work. On Windows Server 2008 R2, Windows 7, and Windows Server 2008, be sure to install the full Microsoft .NET Framework 4.5 package prior to installing WMF 4.0 or DSC may not work correctly. 134 | 135 | We may consider automatically installing and configuring DSC in a future release of the plugin. 136 | 137 | ## Uninstallation 138 | 139 | ```vagrant plugin uninstall vagrant-dsc``` 140 | 141 | ## Development 142 | 143 | Before getting started, read the Vagrant plugin [development basics](https://docs.vagrantup.com/v2/plugins/development-basics.html) and [packaging](https://docs.vagrantup.com/v2/plugins/packaging.html) documentation. 144 | 145 | You will need Ruby 2.1.5 and Bundler v1.12.5 installed before proceeding. 146 | 147 | _NOTE_: it _must_ be bundler v1.12.5 due to a hard dependency in Vagrant at this time. 148 | 149 | ``` 150 | git clone git@github.com:mefellows/vagrant-dsc.git 151 | cd vagrant-dsc 152 | bundle install 153 | ``` 154 | 155 | Run tests: 156 | ``` 157 | bundle exec rake spec 158 | ``` 159 | 160 | Run Vagrant in context of current vagrant-dsc plugin: 161 | ``` 162 | cd 163 | bundle exec vagrant up 164 | ``` 165 | 166 | There is a test Vagrant DSC setup in `./development` that is a good example of a simple acceptance test. 167 | 168 | ### Multiple Bundlers? 169 | 170 | If you have multiple Bundler versions, you can still use 1.12.5 with the following: 171 | 172 | ``` 173 | bundle _1.12.5_ 174 | ``` 175 | 176 | e.g. `bundle _1.12.5_ exec rake spec` 177 | 178 | ### Visual Studio Code 179 | 180 | You can run the test from Visual Studio Code. This needs the binstubs from bundler. Run 181 | ``` 182 | bundler install --binstubs 183 | ``` 184 | to get them. 185 | 186 | After this you can run the tests with F5. 187 | 188 | ## Contributing 189 | 190 | 1. Fork it ( https://github.com/[my-github-username]/vagrant-dsc/fork ) 191 | 1. Create your feature branch (`git checkout -b my-new-feature`) 192 | 1. Commit your changes, including relevant tests (`git commit -am 'Add some feature'`) 193 | 1. Squash commits & push to the branch (`git push origin my-new-feature`) 194 | 1. Create a new Pull Request 195 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require 'rspec/core/rake_task' 3 | task :default => [:test, :quality] 4 | # Remove 'install' task as the gem is installed to Vagrant, not to system 5 | Rake::Task[:install].clear 6 | namespace :test do 7 | RSpec::Core::RakeTask.new('unit') do |task| 8 | task.pattern = 'spec/**/*_spec.rb' 9 | end 10 | end 11 | desc "Run all tests" 12 | task :test => ['test:unit'] 13 | task :spec => :test -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | install: 2 | - set PATH=C:\Ruby22\bin;%PATH% 3 | - gem install bundler -v 1.12.5 4 | - bundle _1.12.5_ install 5 | 6 | build: off 7 | 8 | before_test: 9 | - ruby -v 10 | - gem -v 11 | - bundle -v 12 | 13 | test_script: 14 | - bundle _1.12.5_ exec rake spec 15 | -------------------------------------------------------------------------------- /development/reboot/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | $shell_script = <