Skip to content

Instantly share code, notes, and snippets.

@amaltson
Last active June 5, 2020 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amaltson/f763531bb2689ad311ed to your computer and use it in GitHub Desktop.
Save amaltson/f763531bb2689ad311ed to your computer and use it in GitHub Desktop.
Kitchen.yml for Windows
---
driver:
name: vagrant
provisioner:
name: chef_zero
platforms:
- name: windows-7
transport:
name: winrm
driver:
guest: :windows
box: windows-7-test-kitchen
box_url: http://internal-url
winrm:
username: <some username>
password: <some password>
gui: true
suites:
- name: default
run_list:
- recipe[some-recipes]
attributes:
source 'https://rubygems.org'
group :development do
# ChefDK
gem 'berkshelf', '3.1.3'
gem 'nokogiri', '1.6.4.1'
gem 'pry', '~> 0.10.1'
end
group :test do
# ChefDK
gem 'chefspec', '4.0.1'
gem 'foodcritic', '4.0.0'
gem 'test-kitchen', git: 'https://github.com/mwrock/test-kitchen', branch: 'WinRM'
gem 'kitchen-vagrant', git: 'https://github.com/afiune/kitchen-vagrant', branch: 'WinRM'
gem 'kitchen-docker', '~> 1.5'
gem 'rake', '~> 10.3'
end
vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'windows-7-test-kitchen'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: test_default_1422970648952_22381
==> default: Fixed port collision for 5985 => 55985. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 5985 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => /Users/arthur/vms/test
==> default: Running provisioner: shell...
default: Running: inline PowerShell script
# This is the Vagrantfile that 'vagrant package' made that's bundled with the Vagrant box
Vagrant::Config.run do |config|
# This Vagrantfile is auto-generated by `vagrant package` to contain
# the MAC address of the box. Custom configuration should be placed in
# the actual `Vagrantfile` in this box.
config.vm.base_mac = "0800275297C3"
end
# Load include vagrant file if it exists after the auto-generated
# so it can override any of the settings
include_vagrantfile = File.expand_path("../include/_Vagrantfile", __FILE__)
load include_vagrantfile if File.exist?(include_vagrantfile)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "windows-7-test-kitchen"
config.vm.guest = :windows
config.vm.communicator = "winrm"
config.vm.base_mac = "080027527704"
config.vm.provider "virtualbox" do |v|
v.gui = true
end
config.winrm.username = "<account>"
config.winrm.password = "<password>"
config.vm.provision "shell", inline: '"Hello World" | Out-File C:\chef.txt'
end
@mwrock
Copy link

mwrock commented Feb 3, 2015

Lots has changed here. This is the best way to make sure you have the latest good bits:

Here is how I build my vagrant workstation and our build agents:

#this installs the winrm compatible fork of test-kitchen
test_kitchen_winrm_dir = '/var/cache/test-kitchen'
directory test_kitchen_winrm_dir

git test_kitchen_winrm_dir do
  repository 'https://github.com/test-kitchen/test-kitchen'
  revision 'windows-guest-support'
end

bash 'build and overlay test-kitchen fork' do
  cwd test_kitchen_winrm_dir
  code <<-EOS
    gem build test-kitchen.gemspec
    cp -r /var/cache/test-kitchen/lib /opt/chefdk/embedded/apps/test-kitchen
    cp -r /var/cache/test-kitchen/support /opt/chefdk/embedded/apps/test-kitchen
  EOS
end

gem_package "test-kitchen" do
  source "/var/cache/test-kitchen/test-kitchen-1.3.2.dev.gem"
  gem_binary "/opt/chefdk/embedded/bin/gem"
  options "--no-user-install"
  version "1.3.2.dev"
  action :upgrade
end

As for the kitchen-Vagrant driver, get it from https://github.com/afiune/kitchen-vagrant - the Transport branch

@amaltson
Copy link
Author

amaltson commented Feb 3, 2015

Thanks again @mwrock, the missing bits for me was which specific Git branches to use as the custom test-kitchen and kitchen-vagrant gems to use.

@amaltson
Copy link
Author

amaltson commented Feb 3, 2015

Nevermind, I've gotten further now by providing my own vagrantfile_erb, it can successfully kitchen create, but now it's failing on the converge:

$ bundle exec kitchen converge
-----> Starting Kitchen (v1.3.2.dev)
-----> Converging <default-windows-7>...
       Preparing files for transfer
       Preparing dna.json
       Resolving cookbook dependencies with Berkshelf 3.1.3...
       Removing non-cookbook files before transfer
       Preparing validation.pem
       Preparing client.rb
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #converge action: [[Kitchen::Transport::Winrm] WinRM::WinRMAuthorizationError using shell: [powershell] and command: [ $ProgressPreference='SilentlyContinue';   if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };
  if (-Not (Test-Path "/tmp/kitchen")) {
    mkdir "/tmp/kitchen" | Out-Null
  }
if ( Test-Path '/tmp/kitchen/data' ) { rm -r '/tmp/kitchen/data' };if ( Test-Path '/tmp/kitchen/data_bags' ) { rm -r '/tmp/kitchen/data_bags' };if ( Test-Path '/tmp/kitchen/environments' ) { rm -r '/tmp/kitchen/environments' };if ( Test-Path '/tmp/kitchen/roles' ) { rm -r '/tmp/kitchen/roles' };if ( Test-Path '/tmp/kitchen/clients' ) { rm -r '/tmp/kitchen/clients' };]]
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

@andrewcng
Copy link

I got the exact same error when using Vagrant 1.7.2. kitchen create works fine, but converge fails. I downgraded to Vagrant 1.6.3 and the issue didn't seem to manifest anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment