2

Is it possible to handle automatic upgrades of VM guests which differ only in terms of config management? I'm asking about either general or specific technologies which facilitate this. In brief, I have a number of CentOS/Debian installs which can be thought of as a clean install + puppet config. I wish to perform, in an automated manner, a yum update or equivalent (apt-get upgrade), or installing package X. I want this to occur by taking my VM template, upgrading the OS there, and then re-deploying each VM based on that template one by one (after I eyeball the template to ensure nothing's broken).

I don't care if it's ESXi or XenServer or openvz or anything in between. I don't mind having to install 3rd party tools. I'm aware of XenServer rolling pool upgrades, but that's for the hosts only afaik.

  • 1
    Not exactly sure what you're describing... – ewwhite Dec 19 '14 at 5:31
  • Can you tell me what about it is unclear? I'm happy to improve the question, but I think this is a case of "I don't know what I don't know". I want to 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. – user41758 Dec 19 '14 at 14:55
3

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

| improve this answer | |
  • Yeah, sort of, except I'm looking for some kind of tool out there which will automate the process of killing the old, building a new VM, rolling the config etc. DNS should not have to change as it would take the same network config as the old one. – user41758 Dec 19 '14 at 15:02
  • +1 for your scripting so far, cheers for that! So, right now we've automated the first step of upgrading the template. The guest re-deployment is actually the linchpin of the question, as well as clearly the more complicated step. I suppose it'd have to be environment-specific and iterate over named VMs using PowerCLI. – user41758 Dec 23 '14 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy