Top Banner
Webinar: Cooking with Chef on Microsoft Windows Julian C. Dunn Senior Consultant, Opscode, Inc. <[email protected]>
29

Opscode Webinar: Cooking with Chef on Microsoft Windows

May 07, 2015

Download

Technology

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Opscode Webinar: Cooking with Chef on Microsoft Windows

Webinar:Cooking with Chef on Microsoft WindowsJulian C. Dunn

Senior Consultant, Opscode, Inc.

<[email protected]>

Page 2: Opscode Webinar: Cooking with Chef on Microsoft Windows

Introduction to Opscode and Chef

Page 3: Opscode Webinar: Cooking with Chef on Microsoft Windows

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:

“”

Page 4: Opscode Webinar: Cooking with Chef on Microsoft Windows

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)

Page 5: Opscode Webinar: Cooking with Chef on Microsoft Windows

Notable Chef Customers on Windows

Page 6: Opscode Webinar: Cooking with Chef on Microsoft Windows

Automating a .NET App on Windows

Page 7: Opscode Webinar: Cooking with Chef on Microsoft 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

Page 8: Opscode Webinar: Cooking with Chef on Microsoft 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

Page 9: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 10: Opscode Webinar: Cooking with Chef on Microsoft Windows

Video

Page 11: Opscode Webinar: Cooking with Chef on Microsoft Windows

The Recipe Code

Page 12: Opscode Webinar: Cooking with Chef on Microsoft Windows

nopCommerce Recipe Code: Install IIS, ASP.NET 4.5

Page 13: Opscode Webinar: Cooking with Chef on Microsoft Windows

nopCommerce Recipe Code: Install nopCommerce

Page 14: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 15: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 16: Opscode Webinar: Cooking with Chef on Microsoft Windows

The Result

Page 17: Opscode Webinar: Cooking with Chef on Microsoft Windows

Overview of Chef Resources on Windows

Page 18: Opscode Webinar: Cooking with Chef on Microsoft 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

Page 19: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 20: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 21: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 22: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 23: Opscode Webinar: Cooking with Chef on Microsoft Windows

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?

Page 24: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 25: Opscode Webinar: Cooking with Chef on Microsoft 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

Page 26: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 27: Opscode Webinar: Cooking with Chef on Microsoft Windows

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

Page 28: Opscode Webinar: Cooking with Chef on Microsoft Windows

Wrap Up / Q&A

Page 29: Opscode Webinar: Cooking with Chef on Microsoft Windows

Wrap-Up and Q&A

• Much more than what’s shown here!

• Blog posts and other webinars to come

• Questions?

Thank you!

E: [email protected]

W: www.opscode.com/blog

T: @julian_dunn

G: github.com/juliandunn