Opscode Webinar: Cooking with Chef on Microsoft Windows


Published on

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.

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Chef is a framework for building and managing servers, systems and software packages. Chef relies on abstract definitions (known as cookbooks and recipes) that describe how specific parts of your infrastructure should be built and managed. These recipes and cookbooks are managed like source code, kept centrally in a version-controlled repository, and made re-usable across your infrastructure. - When a new server comes online, the only thing that Chef needs to know is which of your centrally stored cookbooks and recipes to apply (ie “this new server or sets of servers should be apache webservers”)- Subsequently, making changes is as simple as pushing a single update and watching Chef roll it out to all of the servers for which that update applies. One of our customers may have described it best when he referred to Chef as “a fleet of little systems engineer robots who do all your dirty work for you”The result is a method for managing infrastructure that is an order of magnitude more scalable and flexible than prior generations. Our customers refer to this as "infrastructure as code".
  • We have many others.
  • Available through WebPI, but not 100% automated (and WebPI install is very opinionated)This is a good use case to have more control over what's on the system rather than using WebPI- Also show off some of the resources & tuning that I like to do for a base Windows system
  • Tell them I’ll walk through actual code once the video is done
  • - Knife-azure call out to Azure API to create a machineWhen machine is ready, connect to it over WinRMSend information about Chef server from local workstation to remote automaticallyInstall Chef-Run Chef for the first time with the desired "run list" (list of things to do) -- register node with Chef server, start running through cookbooks and recipes in order Scroll through the output, you can see Chef doing all the things I asked for in the run listLoad the webpage as the final step to prove that it's installed -- I didn't go so far as to automate the creation of the SQL database, etc. but I could, we have cookbooks for that!
  • Here we set up IIS properly with all the extensions we needI’m not using the “iis” cookbook but we could have done that too, but I didn’t want webpi on my system.
  • Download and unpack nopCommerce, set up its permissions properly
  • Code Can! Change your logos.
  • Again, reiterate what a “resource” is in the context of Chef
  • Not gonna show “batch” in this webinar, just mention that “batch” is for running CMD.EXE format scripts
  • “mode”: Microsoft Windows: The octal mode that is translated into rights for Microsoft Windows security. Values up to 0777 are allowed (no sticky bits) and mean the same in Microsoft Windows as they do in UNIX, where 4 equals GENERIC_READ, 2 equals GENERIC_WRITE, and 1 equals GENERIC_EXECUTE. This attribute cannot be used to set :full_control. This attribute has no effect if not specified, but when this attribute and rights are both specified, the effects will be cumulative.
  • WindowsRebootHandler – if registered, fires at end of successful Chef runs and acts on requested (by Chef resources) or pending (determined by the OS) reboots.Windows_reboot resource can be used by your code to set whether a reboot is required, which will be picked up by said handler
  • Tell them that anything I can’t answer, I’ll post answers on the blog.Also, feel free to ask questions through the blog and I’ll respond, or get someone at Opscode to respond.
  • Opscode Webinar: Cooking with Chef on Microsoft Windows

    1. 1. Webinar: Cooking with Chef on Microsoft Windows Julian C. Dunn Senior Consultant, Opscode, Inc. <jdunn@opscode.com>
    2. 2. Introduction to Opscode and Chef
    3. 3. 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:
    4. 4. 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)
    5. 5. Notable Chef Customers on Windows
    6. 6. Automating a .NET App on Windows
    7. 7. 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
    8. 8. 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
    9. 9. 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
    10. 10. Video
    11. 11. The Recipe Code
    12. 12. nopCommerce Recipe Code: Install IIS, ASP.NET 4.5
    13. 13. nopCommerce Recipe Code: Install nopCommerce
    14. 14. nopCommerce Recipe Code: Set up IIS Site, App Pool, App
    15. 15. Other Recipe Code You Might Have Noticed cookbook_file 'C:WindowsSystem32oemlogo.bmp' do source node['windowshacks']['oeminfo']['logofile'] rights :read, "Everyone" action :create end registry_key 'HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionOEMInformation' do values [{:name => 'Logo', :type => :string, :data => 'C:WindowsSystem32oemlogo.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 :create end
    16. 16. The Result
    17. 17. Overview of Chef Resources on Windows
    18. 18. 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
    19. 19. 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
    20. 20. 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
    21. 21. 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 'HKCUSoftwareMicrosoftWindowsCurrentVersionInternet 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
    22. 22. 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
    23. 23. 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?
    24. 24. Special File and Directory Permissions Handling on Windows • Parameters that don‟t make sense are ignored • DOMAINuser, DOMAINgroup work • Filesystem ACLs are different on Windows • mode parameter semantics • rights parameter only for Windows
    25. 25. 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
    26. 26. 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
    27. 27. 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
    28. 28. Wrap Up / Q&A
    29. 29. 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