Opscode Webinar: Cooking with Chef on Microsoft Windows

Preview:

DESCRIPTION

Slides from 08-27-2013 Opscode webinar on using Chef to automate your Microsoft Windows-based infrastructure, including a live demo of Windows automation and a review of the latest and greatest resources available for running Chef with Windows-based infrastructure.

Citation preview

Webinar:Cooking with Chef on Microsoft WindowsJulian C. Dunn

Senior Consultant, Opscode, Inc.

<jdunn@opscode.com>

Introduction to Opscode and Chef

What is Chef?

Recipes and Cookbooks that describe and deliver code.

Chef enables people to easily build & manage complex & dynamic applications at massive scale.

•New model for describing infrastructure that promotes reuse

•Programmatically provision and configure

•Reconstruct business from code repository, data backup, and bare metal resources

Chef is an IT automation platform for developers & systems engineers to continuously define, build, and manage infrastructure.

CHEF USES:

“”

Chef and Windows Support Milestones

•May 2011 – Knife plugin for Windows announced

•Oct 2011 – PowerShell, IIS, SQL Server, and Windows cookbooks

•Dec 2011 – Chef Client Installer MSI for Microsoft Windows

•Feb 2012 – Integration of the registry_key resource into core Chef from the Windows cookbook

•Aug 2013 – Chef 11.6.0 release. PowerShell and Batch scripting integrated into core Chef. Chef Client released as Windows service

•Aug 2013 - PowerShell Desired State Configuration support announced (for delivery later in 2013)

Notable Chef Customers on Windows

Automating a .NET App on Windows

Automating a .NET App on Windows

• The app: nopCommerce Shopping Cart solution (www.nopcommerce.com)

• ASP.NET with SQL Server backend

• Available through WebPI

• WebPI install assumes a lot, however

• Full-featured app suitable to show off Chef resources on Windows

Resources Automated in this Demo

• Installing Windows Features and Roles

• IIS app pool

• IIS site

• IIS app

• Registry settings

• Deploying files onto the system

• Unzipping files 

• Windows filesystem rights management

Provisioning with Chef

• Beta of the Azure plugin for Chef

• Request new VM from Azure API

• Bootstrap it over WinRM

• Install and start Chef

• Register with Chef server

• Run through the “run list”

• Instant infrastructure with one command

Video

The Recipe Code

nopCommerce Recipe Code: Install IIS, ASP.NET 4.5

nopCommerce Recipe Code: Install nopCommerce

nopCommerce Recipe Code: Set up IIS Site, App Pool, App

Other Recipe Code You Might Have Noticed

cookbook_file 'C:\Windows\System32\oemlogo.bmp' do source node['windowshacks']['oeminfo']['logofile'] rights :read, "Everyone" action :createend

registry_key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation' do values [{:name => 'Logo', :type => :string, :data => 'C:\Windows\System32\oemlogo.bmp'}, {:name => 'Manufacturer', :type => :string, :data => node['windowshacks']['oeminfo']['manufacturer']}, {:name => 'SupportHours', :type => :string, :data => node['windowshacks']['oeminfo']['supporthours']}, {:name => 'SupportPhone', :type => :string, :data => node['windowshacks']['oeminfo']['supportphone']}, {:name => 'SupportURL', :type => :string, :data => node['windowshacks']['oeminfo']['supporturl']}] action :createend

The Result

Overview of Chef Resources on Windows

Chef Resources on Windows: Same as UNIX/Linux

• file, remote_file, cookbook_file, template

• directory, remote_directory

• user, group

• mount (can take CIFS paths)

• env

• service

• execute

• ruby_block

• many others...Photo Credit: L. Allen Brewer

Windows-Only Resources

• registry_key (new in Chef 11.0.0)

• powershell_script (new in Chef 11.6.0)

• batch (new in Chef 11.6.0)

• Automatic architecture handling (:i386 vs. :x86_64)

• Automatic Windows filesystem redirector handling (Wow64)

• Long-term roadmap: move more resources to core and out of ‘windows’ cookbook

Windows-Only Cookbooks

• By Opscode:

• 7-zip

• iis

• powershell

• sql_server

• webpi

• windows

• wix

• Many others in the community

• couchbase

• ms_dotnet45

• (to name but a few) Photo Credit: Marc Falardeau

registry_key example

# Set system’s proxy settings to be the same as used for Chef

proxy = URI.parse(Chef::Config[:http_proxy])

registry_key 'HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings' do

values [{:name => 'ProxyEnable', :type => :reg_dword, :data => 1},

{:name => 'ProxyServer', :data => "#{proxy.host}:#{proxy.port}"},

{:name => 'ProxyOverride', :type => :reg_string, :data => '<local>'}]

action :create

end

powershell_script example

powershell_script "rename hostname" do

code <<-EOH

$computer_name = Get-Content env:computername

$new_name = 'test-hostname'

$sysInfo = Get-WmiObject -Class Win32_ComputerSystem

$sysInfo.Rename($new_name)

EOH

end

Registry Idempotency Helpers

• Resources like powershell_script are not idempotent by default

• We provide some helpers for checking the registry:

• registry_data_exists?

• registry_get_subkeys

• registry_get_values

• registry_has_subkeys?

• registry_key_exists?

• registry_value_exists?

Special File and Directory Permissions Handling on Windows

• Parameters that don’t make sense are ignored

• DOMAIN\user, DOMAIN\group work

• Filesystem ACLs are different on Windows

• mode parameter semantics

• rights parameter only for Windows

The “windows” cookbook

• The windows cookbook includes a number of resources and providers, and helper libraries.

• See https://github.com/opscode-cookbooks/windows for a full list

• Highlights:

• windows_auto_run

• windows_feature

• windows_package

• windows_path

• windows_reboot

• windows_zipfile

• Other: windows_printer, windows_printer_port, windows_task

Photo Credit: peyri

Helper Functions in Windows Cookbook

• Libraries (include Windows::Helper):

• win_friendly_path - ensures backslashes are used everywhere

• win_version:

• server_core? server_full? server_datacenter?

• windows_7? windows_server_2008_r2? etc.

Photo Credit: ilovecocacola

Windows Report Handlers

• Windows cookbook:

• WindowsRebootHandler

• windows_reboot resource

• windows::reboot_handler recipe

• Eventlog cookbook:

• Send Chef output to Windows Event Log

Photo Credit: blakespot

Wrap Up / Q&A

Wrap-Up and Q&A

• Much more than what’s shown here!

• Blog posts and other webinars to come

• Questions?

Thank you!

E: jdunn@opscode.com

W: www.opscode.com/blog

T: @julian_dunn

G: github.com/juliandunn

Recommended