I have come up with a way to deploy patches via Chef using 'batch' to call the cmd file that I use for how-to-script-citrix-and-ms-hot-fixes for RDSH and Citrix XA servers page.
My question that I am hoping to get answered is the following : Can windows_package call wusa.exe?
Here is what I am doing, is anyone doing similar or better process? I am really new to #getchef and ruby so I am just pulling from some of the stuff that I have done on Altiris to get it working then add in attributes after it works correctly. If anyone has some better suggestions on how to do it or coding best practices, feel free to comment. It is primitive, but it works.
w2k8_post_sp1_hotfixes
recipes::default.rb
#
# Cookbook Name:: w2k8_post_sp1_hotfixes
# Recipe:: default
#
# Copyright (C) 2013 Todd Pigram
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# make dir
batch node[:w2k8hf][:make] do
code <<-EOH
mkdir c:\\PostSP1
EOH
not_if {::File.exists?(node[:w2k8hf][:sleep])}
not_if {reboot_pending?}
end
# download patches to server
# unzip patches to c:\
windows_zipfile node[:w2k8hf][:zip] do
source node[:w2k8hf][:url]
action :unzip
not_if {::File.exists?(node[:w2k8hf][:sleep])}
not_if {reboot_pending?}
end
# Install patches
batch node[:w2k8hf][:install] do
code <<-EOH
cd c:\\PostSp1
c:\\postsp1\\installpostsp1.cmd
EOH
not_if {::File.exists?(node[:w2k8hf][:log])}
not_if {reboot_pending?}
end
batch node[:w2k8hf][:remove] do
code <<-EOH
rmdir /s /q c:\\PostSp1
EOH
only_if {::File.exists?(node[:w2k8hf][:log])}
not_if {reboot_pending?}
end
# if feature installs, schedule a reboot at end of chef run
windows_reboot 60 do
reason 'cause chef said so'
only_if {reboot_pending?}
end
attributes::default.rb
#
# Cookbook Name:: w2k8_post_sp1_hotfixes
# Recipe:: default
#
# Copyright (C) 2013 Todd Pigram
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
default[:w2k8hf][:make] = "make dir"
default[:w2k8hf][:remove] = "remove c:\\PostSp1"
default[:w2k8hf][:url] = "http://yourdomain.com/PostSP1.zip"
default[:w2k8hf][:install] = "install"
default[:w2k8hf][:log] = "C:/PostSp1_patches.log"
default[:w2k8hf][:sleep] = "C:/PostSp1/sleep.exe"
default[:w2k8hf][:zip] = "c:/PostSP1"
libraries::reboot_pending.rb - This is needed as I run this as part of the run list that takes a server from template all the way to having the XD 7.1 VDA installed.
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
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 Ruby. Show all posts
Showing posts with label Ruby. Show all posts
Tuesday, December 10, 2013
Thursday, November 28, 2013
Happy Thanksgiving. Keeping with the food theme....
I have been spending my vacation messing around with Opscode #Chef, #Bento, #Packer, #Berkshelf, #Foodcritic, #Vagrant, #Virtualbox and #Veewee. As a beginning Rubyist and being new to Chef, the learning curve is quite steep. While I should be spending my time with my Linux courses from www.linuxacademy.com, I have deadlines to meet with automated builds and configuration management.
Most of what I am creating is for Windows OSes. As there are not really any books written for Chef for windows, I am using what I know from doing all this on Altiris. By doing this, I have cookbooks that will install default configuration for both W2k8r2 and w2012 along with RDS for both. I have put my Citrix Optimization file into a cookbook. I even have cookbooks that will install, but not configure XD7. While these work well, they are primitive based on good development standards.
Thanks to Alex Vinyar from Opscoode for the code to allow pending reboots!!!!
While messing with Berkshelf last night and today, there is a great article by Jamie Winsor (jamie@vialstudios.com), authoring cookbooks that really opened my eyes at the stuff I need to do with my cookbooks and recipes...
That is what I will be doing the rest of my vacation, making my code less primitive or maybe take a break and study some linux...I might do both...
I also need to figure out have to configure berkshelf to use my different organizations on Hosted Chef. I assume just berks configure and modify the chef settings along changing the berkshelf location for each repo... more testing to really understand it all...
Most of what I am creating is for Windows OSes. As there are not really any books written for Chef for windows, I am using what I know from doing all this on Altiris. By doing this, I have cookbooks that will install default configuration for both W2k8r2 and w2012 along with RDS for both. I have put my Citrix Optimization file into a cookbook. I even have cookbooks that will install, but not configure XD7. While these work well, they are primitive based on good development standards.
Thanks to Alex Vinyar from Opscoode for the code to allow pending reboots!!!!
While messing with Berkshelf last night and today, there is a great article by Jamie Winsor (jamie@vialstudios.com), authoring cookbooks that really opened my eyes at the stuff I need to do with my cookbooks and recipes...
That is what I will be doing the rest of my vacation, making my code less primitive or maybe take a break and study some linux...I might do both...
I also need to figure out have to configure berkshelf to use my different organizations on Hosted Chef. I assume just berks configure and modify the chef settings along changing the berkshelf location for each repo... more testing to really understand it all...
Labels:
Berkshelf,
Chef,
Foodcritic,
Opscode,
Packer,
Ruby,
Vagrant,
Veewee,
Virtualbox
Saturday, November 16, 2013
Tuesday, September 13, 2011
Subscribe to:
Posts (Atom)
