In short, you are wanting to build a template. On your maintenance schedule, convert it to a virtual machine, boot the new virtual machine, run sudo yum -y update ; sudo shutdown -h now
.
Once it is down, convert back to a template from a live VM. Since you have configuration management already in-place, you would simply build a new VM matching the manifests of the old one, and roll the configuration to the new one, swap the DNS records and kill the old one.
I have not seen a canned tool to perform this job, but the VMWare PowerCLI (PowerShell plugin for VMWare VCenter) can convert between templates and VMs using the Set-VM -ToTemplate
and the Set-Template -ToVM
commands[1].
Once you have the VM (the live representation of the template) up and running, you can issue commands into the guest using the Invoke-VMScript
command[2], such as issuing your yum commands [3].
I was playing with the idea of this, and have a Q&D weekend hack. I have not tested this script, and it is almost certainly wrong, but here is the basic idea to get you started. Note, it has some bad ideas, like including a password in a script, or assuming a flat name-space for your VMs and Templates.
#################################
## Convert a VMWare template to a running
## system, apply maintenance, then convert
## back to a template
##
## Note, this naively does not do any error-
## checking and does not specify much info
##
## Please adapt to your environment
##
#################################
Param {
[string] $templatename ;
}
$RHELPasswd = 'P@$$w0rd!' ;
if(! $templatename) {
Write-Error "Please pass the name of the template on the command-line" ;
exit(-1) ;
}
if(Get-Template -Name $templatename) {
$vm = Set-Template -Template $templatename -ToVM ;
$guestscript = 'sudo yum -y update ; sudo shutdown -h now' ;
Invoke-VMScript -VM $vm -ScriptText $guestscript -GuestUser 'root' -GuestPassword $RHELPasswd ;
Get-VM $vm |Set-VM -ToTemplate -name $templatename ;
}
1: http://www.mikelaverick.com/2014/06/back-to-basics-creating-and-deploying-templates-with-powercli-part-7/ [4] and [5]
2: https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Invoke-VMScript.html
3: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/ch-yum.html#sec-Checking_For_and_Updating_Packages
4: https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Set-VM.html
5: https://www.vmware.com/support/developer/PowerCLI/PowerCLI41U1/html/Set-Template.html
yum -y update
a VM template of which I have instantiations, and then run an automated procedure to snapshot each guest VM using the template, shut it down, start a fresh copy of the new (upgraded) template, and set some basic identifying information such that a puppet request will apply the right config to it.