Showing posts with label #Chef. Show all posts
Showing posts with label #Chef. Show all posts

Friday, October 3, 2014

DevOpsCLE - MeetUp - Thoughts and impressions

MeetUp - DevOpsCLE

As my first MeetUp ever, I had the opportunity to present on DevOps and Windows. I posted the slide deck in a separate post last night so I won't include it again. The MeetUp was at LeanDog which is an awesome place that is actually a boat, I am not kidding. The atmosphere was very laid back and everyone was really welcoming.

As this was my first public presentation on how I am using Chef with Windows, besides evangelizing it at the office and a posting here, I feel that it went pretty well. We had 7-8 people in attendance, ranging from Linux developers, .Net programmers to Sysadmins(Linux/Windows). I did the basic presentation then proceeded to do a live demo with a Vagrant Windows 2012r2 server. I actually turned the server into a terminal server to show how Chef handles pending reboots. In the future, as a mental not to myself, increase the Ram on the VM....:)

To me the actual best part was the Q/A afterwards. We discussed the philosophy of what DevOps really is and how it can accelerate pretty much everything if everyone would just work together and understand the benefit to the business as a whole.

As an added benefit, I picked up some coding tips from some much better Rubyists than I...now time test and learn more. I really look forward to what is coming next...

You should check out the group and join us!

Sunday, August 31, 2014

Updated Windows_Pagefile Cookbook #gethchef

I modified the default.rb to separate w2012/w2012r2 and w2k8r2 for both XenServer and vCloud/vSphere with the Ohai value for [kernel][cs_info][total_physical_memory]. I have broken it down for XenServer (4gb, 6gb, 8gb, 16gb) then vCloud/vSphere (4gb, 6gb, 8gb, 16gb).

The cookbook is on GitHub.

Here is the new default.rb:

def memory
  "#{node['kernel']['cs_info']['total_physical_memory']}"
end

# splitting out based on OS vsersion and then the case statement is XenServer(4,6,8,16) then vSphere/vCloud(4,6,8,16)
if node['platform_version'] >= "6.2.9200"
  case memory
  when "4286169088"
    include_recipe "pagefile::4gb"
  when "6433652736"
    include_recipe "pagefile::6gb"
  when "8581136384"
    include_recipe "pagefile::8gb"
  when "17171070976"
    include_recipe "pagefile::16gb"
  when "4294496256"
    include_recipe "pagefile::4gb"
  when "6441979904"
    include_recipe "pagefile::6gb"
  when "8589463552"
    include_recipe "pagefile::8gb"
  when "17179398144"
    include_recipe "pagefile::16gb"
  end
else
  case memory
  when "4290367488"
    include_recipe "pagefile::4gb"
  when "6437851136"
    include_recipe "pagefile::6gb"
  when "8585334784"
    include_recipe "pagefile::8gb"
  when "17175269376"
    include_recipe "pagefile::16gb"
  when "4294500352"
    include_recipe "pagefile::4gb"
  when "6441984000"
    include_recipe "pagefile::6gb"
  when "8589467648"
    include_recipe "pagefile::8gb"
  when "17179402240"
    include_recipe "pagefile::16gb"
  end
end

Tuesday, August 19, 2014

Chef and Windows Reboots - My personal experience #getchef

I have been seeing a few posts on issues with Windows reboots and Chef. I actually had this issue last year while trying to decide between Puppet and Chef. I posted on the issue on here back in either Nov or October 2013.

Alex Vinyar, from then Opscode, now Chef, provided me with a custom library file that I have used since up until it was added to chef on, I believe, in version 11.12 of the Chef Client.

All I had to do was make sure you include windows::reboot_handler first in the nodes run list or role.

 Then include a not_if {reboot_pending?} on your recipes and on the windows_reboot section add a only_if {reboot_pending?}.

Here are couple of examples

Both of these are for deploying RDSH for some Citrix XenApp servers. These are different recipes from the same cookbook.

I do have the custom library file in this cookbook

library/reboot_pending.rb

class Chef
  class Resource
    # include Chef::Mixin::ShellOut

    def reboot_pending?
      # Any files listed here means reboot needed
      (Registry.key_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations') &&
        Registry.get_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager','PendingFileRenameOperations').any?) ||
      # 1 for any value means reboot pending
      # "9306cdfc-c4a1-4a22-9996-848cb67eddc3"=1
      (Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') &&
        Registry.get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired').select{|v| v[2] == 1 }.any?) ||
      # 1 or 2 for 'Flags' value means reboot pending
      (Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
        [1,2].include?(Registry::get_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile','Flags'))) ||
      # added by Alex
      Registry.key_exists?('HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending')
    end

  end
end



w2k8r2.rb - Using powershell code I have found its easier to split them up.

# install RDS
powershell node['w2k8']['rds'] do
  code <<-eoh p="">  Import-Module ServerManager
  Add-WindowsFeature RDS-RD-Server
  EOH
  not_if {reboot_pending?}
end


# Install desktop experience
powershell node['w2k8']['deskexp'] do
  code <<-eoh p="">  Import-Module ServerManager
  Add-WindowsFeature Desktop-Experience
  EOH
  not_if {reboot_pending?}
end

powershell node['w2k8']['xps'] do
  code <<-eoh p="">  Import-Module ServerManager
  Add-WindowsFeature XPS-Viewer
  EOH
  not_if {reboot_pending?}
end

windows_reboot 30 do
  reason 'Chef said to'
  only_if {reboot_pending?}
end

w2012r2.rb

%w{ Xps-Foundation-Xps-Viewer Remote-Desktop-Services ServerMediaFoundation AppServer DesktopExperience }.each do |feature|
  windows_feature feature do
    action :install
    not_if {reboot_pending?}
  end
end

windows_reboot 30 do
  reason 'Chef said to'
  only_if {reboot_pending?}
end

Per the latest windows cookbook :


Attributes

  • node['windows']['allow_pending_reboots'] - used to configure the WindowsRebootHandler (via the windows::reboot_handler recipe) to act on pending reboots. default is true (ie act on pending reboots). The value of this attribute only has an effect if the windows::reboot_handler is in a node's run list.
I have performed some testes on w2012/w2012r2 without the custom library file, and it worked great. I have not tried it on w2k8r2 though....Hope this helps.

Friday, August 15, 2014

Challenges setting up a Chef Pagefile Cookbook

I figured this would be simple...I did it is Altiris without an issue. I have done it with reg files easily. How hard could it be? Well it was tricky. I wanted to leverage all the cool information that I got from ohai. So I started out like this using a Windows Server 2012R2 VM to grab the ohai results for the various settings.

Abandoned
default.rb

case node['kernel']['cs_info']['total_physical_memory']
when "2147012608"
  include_recipe "pagefile::2gb"
when "4294496256"
  include_recipe "pagefile::4gb"
when "6441979904"
  include_recipe "pagefile::6gb"
when "6437851136"
  include_recipe "pagefile::6gb"
when "8585334784"
  include_recipe "pagefile::8gb"
when "17171070976"
  include_recipe "pagefile::16gb"
end

Then I had corresponding jobs for - 2gb, 4gb, 6gb, 8gb, & 16gb

2gb.rb
windows_pagefile 'c:\pagefile.sys' do
      initial_size (3072)
      maximum_size (3072)
      system_managed false
      automatic_managed false
      action :set
      not_if {reboot_pending?}
    end

Everything was going great. That was until I decided to set a VM that was on Windows Server 2008 R2. The recipe never ran.. So I proceeded to run ohai >c:\w2k8r28gb.txt. Sure enough, even though both VMs had the same 8GB installed, the total_physical_memory was different. So I proceeded to create additional when statements calling the same include_recipe. Ok so everything was running great on my VMs on CloudStack/XenServer.

I decided to test on vSphere and vCloud, guess what, all different...I couldn't believe it..

So I had to come up a completely different way. I tried making variables with ranges to no avail.

I ended up abandoning using ohai and the case in favor of some POSH and if, elsif, else.

Thanks to my buddy, Ron Oberjohann (ron@advdat.com) for help with the POSH. I was use 'Get-WMIObject -class Win32_PhysicalMemory', but wasn't doing the math.

I am seeing if I can still get the ohai portion to work by trying to round that info...time to revisit my Ruby course from last year :)

But for now here is what works:

def memory
  powershell_script "$ram" do
    code <<-eoh p="">    $computer = Get-WMIObject -class "Win32_ComputerSystem"
    $ram = [math]::Round($computer.TotalPhysicalMemory/1024/1024/1024/0)
    EOH
  end
end

if memory == 2
    windows_pagefile 'c:\pagefile.sys' do
      initial_size (3072)
      maximum_size (3072)
      system_managed false
      automatic_managed false
      action :set
      not_if {reboot_pending?}
    end
elsif memory == 4
    windows_pagefile 'c:\pagefile.sys' do
      initial_size (6144)
      maximum_size (6144)
      system_managed false
      automatic_managed false
      action :set
      not_if {reboot_pending?}
    end
elsif memory == 6
    windows_pagefile 'c:\pagefile.sys' do
      initial_size (9216)
      maximum_size (9216)
      system_managed false
      automatic_managed false
      action :set
      not_if {reboot_pending?}
    end
elsif memory == 8
    windows_pagefile 'C:\pagefile.sys' do
      initial_size  (8193)
      maximum_size  (8193)
      system_managed false
      automatic_managed false
      action :set
      not_if {reboot_pending?}
    end
else memory = 16
    windows_pagefile 'c:\pagefile.sys' do
      initial_size (16385)
      maximum_size (16385)
      system_managed false
      automatic_managed false
      action :set
      not_if {reboot_pending?}
    end
  Chef::Log.error("Can't determine memory and set pagefile")
end

The code is on my github. I thought I'd share my findings.