Posts on Security, Cloud, DevOps, Citrix, VMware and others. Words and views are my own and do not reflect on my companies views. Disclaimer: some of the links on this site are affiliate links, if you click on them and make a purchase, I make a commission.
Showing posts with label #Windows Server. Show all posts
Showing posts with label #Windows Server. Show all posts
Thursday, October 2, 2014
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
"#{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
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.-eoh>
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.-eoh>
Subscribe to:
Posts (Atom)