Windows TK Files

119 views
Skip to first unread message

Ryan Hass

unread,
Apr 23, 2014, 5:40:58 PM4/23/14
to testing-...@googlegroups.com
Mischa, I think in the class you mentioned something about having some files for setting up Windows with TK. Would it be possible to send a link out where we can get those examples?

Thanks!

-Ryan H.

Mischa Taylor

unread,
Apr 24, 2014, 8:17:11 AM4/24/14
to testing-...@googlegroups.com
You should have received them with the initial class e-mail - it's the chapter excerpt of "Learning Chef", which is 100% Test Kitchen based.  The instructions are also public here: http://misheska.com/blog/2013/12/26/set-up-a-sane-ruby-cookbook-authoring-environment-for-chef/

Here's the summary - when you first start, you'll want to use the Ruby that is bundled with the Windows Chef Client:

1) Install the Chef Client via http://www.getchef.com/chef/install

2) The install will automatically configure your PATH to point at the Chef Client tools in %HOMEDRIVE%\Opscode\Chef\bin and the embedded Ruby in %HOMEDRIVE%\Opscode\Chef\embedded\bin.  Check to make sure the PATH is set properly by running the following to check the PATH to the ruby executable:

    > where ruby
   C:\opscode\chef\embedded\bin\ruby.exe

or if you are using Powershell:

    PS> get-command ruby

3) You'll need to install some flavor of Unix tools so that you have the ssh binary available to Test Kitchen.  ssh is the only means for Test Kitchen to communicate with sandbox environments presently.  I'd recommend install Git, and it comes bundled with the MSYS GNU Utilities from MinGW packaged in a nice friendly installer (and it installs Git as well!).  Go to http://git-scm.com/download and run the installer.  I would recommend choosing "Run Git and included Unix tools from the Windows Command Prompt" as Test Kitchen expects ssh to be in the PATH.

Make sure you have ssh available by running "where ssh" or "get-command ssh" accordingly, similar to step on.

4) Optional - I recommend that you install a programmer's editor that can handle Unix-style linefeeds, like Notepad++ or Sublime to edit your cookbook files.

5) Assuming that you want to install Vagrant (even if you want to use Docker, you'll need to use vagrant to access a Unix VM with Docker) Install VirtualBox via https://www.virtualbox.org/wiki/Downloads


The book excerpt from Learning Chef also contains an appendix for setting up Test Kitchen with all the various popular cloud providers like Amazon EC2, Google Compute Engine, Rackspace and Digital Ocean.  These instructions work just fine for Windows.


Ryan Hass

unread,
Apr 24, 2014, 7:23:57 PM4/24/14
to testing-...@googlegroups.com
Sorry, I may have misunderstood what you meant in the class. What I mean was to use TK with windows platform definitions to test cookbooks themselves running on Windows.

Mischa Taylor

unread,
Apr 24, 2014, 8:25:41 PM4/24/14
to testing-...@googlegroups.com
Ah Windows on the guests not the hosts.  I have a very experimental way using Test Kitchen with Windows guests but it works.  You may want to wait until Vagrant 1.6 is released, which has much better Windows support, and I hear that Fletcher is planning on enhancing Test Kitchen to support the new Vagrant 1.6 features around Windows.

That being said, here's how I use Test Kitchen with a Windows guest:

1) Start with my Packer templates to create a Windows basebox that also has ssh installed - one of the templates in windows2008r2, windows 2012, windows2012r2, windows7, windows8 or the windows 81 directories: https://github.com/misheska/basebox-packer/tree/master/template  Make sure you use the ones using openssh (without cygwin).  We're working with Microsoft legal to provide you Windows basebox images, but right now you need to use your own media to create the Windows baseboxes

2) Build the box with Chef baked in the image by building it with -var "provisioner=chef" and -var "provisioner_version=latest" (or whatever version of Chef you like) to start.  While you can now pass in an override to get Test Kitchen install Chef using the MSI installer, it's one extra variable in this experimental setup, you don't want at first, until you get everything working.

3) Install the vagrant-windows plugin so vagrant can load up your basebox with "vagrant plugin install vagrant-windows"

4) Here's an excerpt of a working .kitchen.yml with Windows.  (You'll need to bump up the memory as Test Kitchen by default only allocates 256MB which isn't enough to load windows, turn off the use of sudo, and to start, turn off chef omnibus install):

---

driver:

  name: vagrant


provisioner:

  name: chef_solo

  require_chef_omnibus: false

  sudo: false


platforms:

  - name: win2008r2-standard

    driver:

      provider: vmware_fusion

      box: win2008r2-standard

      box_url: file:///Users/misheska/Desktop/win2008r2-standard-chef11.10.4.box

      customize:

        memory: 1536


suites:

  - name: default

    run_list:

    attributes:



To show you there's nothing up my sleeve, here's a Test Kitchen run I just performed on a Windows guest with this setup ;-)


$ bundle exec kitchen create

-----> Starting Kitchen (v1.2.1)

-----> Creating <default-win2008r2-standard>...

       Bringing machine 'default' up with 'vmware_fusion' provider...

       ==> default: Box 'win2008r2-standard' could not be found. Attempting to find and install...

           default: Box Provider: vmware_desktop, vmware_fusion, vmware_workstation

           default: Box Version: >= 0

       ==> default: Adding box 'win2008r2-standard' (v0) for provider: vmware_desktop, vmware_fusion, vmware_workstation

           default: Downloading: file:///Users/misheska/Desktop/win2008r2-standard-chef11.10.4.box

       ==> default: Successfully added box 'win2008r2-standard' (v0) for 'vmware_desktop'!

       ==> default: Cloning VMware VM: 'win2008r2-standard'. This can take some time...

       ==> default: Verifying vmnet devices are healthy...

       ==> default: Preparing network adapters...

       ==> default: Starting the VMware VM...

       ==> default: Waiting for the VM to finish booting...

       ==> default: The machine is booted and ready!

       ==> default: Forwarding ports...

           default: -- 3389 => 3389

           default: -- 5985 => 5985

           default: -- 22 => 2222

       ==> default: Setting hostname...

       ==> default: Configuring network adapters within the VM...

       Vagrant instance <default-win2008r2-standard> created.

       Finished creating <default-win2008r2-standard> (2m25.88s).

-----> Kitchen is finished. (2m26.13s)

Atwood:yy misheska$ bundle exec kitchen converge

-----> Starting Kitchen (v1.2.1)

-----> Converging <default-win2008r2-standard>...

       Preparing files for transfer

       Preparing current project directory as a cookbook

       Removing non-cookbook files before transfer

       Transfering files to <default-win2008r2-standard>

       Finished converging <default-win2008r2-standard> (0m6.28s).

-----> Kitchen is finished. (0m6.54s)



Ryan Hass

unread,
Apr 24, 2014, 9:05:00 PM4/24/14
to testing-...@googlegroups.com
Thanks!

jhsubscribe

unread,
Jun 26, 2014, 7:46:42 AM6/26/14
to testing-...@googlegroups.com
Mischa,

Thanks for your work on this. Do you have a working example with a run list specified? Using your example above I get "Finished converging" but it doesn't actually do anything. Ideally with a recipe containing the following as this caused me problems trialling windows_chef_zero

batch 'test batch' do
code 'echo Hello'
end

I've never been able to get a windows box to successfully converge from test-kitchen.

Thanks,
James

mish...@opscode.com

unread,
Oct 9, 2014, 12:51:07 PM10/9/14
to testing-...@googlegroups.com, j.hey...@gmail.com
Sorry, been awhile, give Sean Porter's plugin a go to get it working over SSH (until TK gets official support): https://github.com/portertech/windows_chef_zero

My workaround stopped working at some point, and then I ended up focusing more on the "Learning Chef" book instead.

I was trying it out with the kitchen-ssh provision and it seems to work. I used your example with this .kitchen.yml:

---
driver:
name: ssh

provisioner:
name: windows_chef_zero

platforms:
- name: centos65
driver:
hostname: 192.168.33.44
username: vagrant
password: vagrant
sudo: no
require_chef_omnibus: false

suites:
- name: default
run_list:
- recipe[testy::default]
attributes:

And here's the TK run - actually does something!

$ kitchen converge
-----> Starting Kitchen (v1.2.1)
-----> Converging <default-centos65>...
Preparing files for transfer
Resolving cookbook dependencies with Berkshelf 3.1.5...
Removing non-cookbook files before transfer
Transfering files to <default-centos65>

C:\Users\vagrant>C:\opscode\chef\bin\chef-client -z --config C:\Windows\Temp\kitchen\client.rb --log_level info --json-attributes C:\Windows\Temp\kitchen\dna.json
[2014-10-09T09:18:23-07:00] INFO: Starting chef-zero on host localhost, port 8889 with repository at repository at C:/Windows/Temp/kitchen
One version per cookbook

[2014-10-09T09:18:26-07:00] INFO: *** Chef 11.16.4 ***
[2014-10-09T09:18:26-07:00] INFO: Chef-client pid: 1772
[2014-10-09T09:18:31-07:00] INFO: Setting the run_list to ["recipe[testy::default]"] from CLI options
[2014-10-09T09:18:31-07:00] INFO: Run List is [recipe[testy::default]]
[2014-10-09T09:18:31-07:00] INFO: Run List expands to [testy::default]
[2014-10-09T0
9:18:31-07:00] INFO: Starting Chef Run for default-centos65
[2014-10-09T09:18:31-07:00] INFO: Running start handlers
[2014-10-09T09:18:31-07:00] INFO: Start handlers complete.
[2014-10-09T09:18:31-07:00] INFO: HTTP Request Returned 404 Not Found : Object not found: /reports/nodes/default-centos65/runs
[2014-10-09T09:18:31-07:00] INFO: Loading cookbooks [te...@0.1.0]
[2014-10-09T09:18:31-07:00] INFO: Storing updated cookbooks/testy/recipes/default.rb in the cache.
[2014-10-09T09:18:31-07:00] INFO: Storing updated cookbooks/testy/README.md in the cache.
[2014-10-09T09:18:31-07:00] INFO: Storing updated cookbooks/testy/me
tadata.json in the cache.
[2014-10-09T09:18:31-07:00] INFO: Processing batch[test batch] action run (testy::default line 7)
[2014-10-09T09:18:31-07:00] INFO: batch[test batch] ran successfully
[2014-10-09T09:18:33-07:00] INFO: Chef Run complete in 1.797455 seconds
[2014-10-09T09:18:33-07:00] INFO: Running report handlers
[2014-10-09T09:18:33-07:00] INFO: Report handlers complete
Finished converging <default-centos65> (0m12.46s).
-----> Kitchen is finished. (0m12.74s)
Reply all
Reply to author
Forward
0 new messages