Invoking Orchestrator Runbooks during a Virtual Machine Manager Service Template Deployment
Not only does System Center Virtual Machine Manager have the ability to deploy complete multi-tier services with flexible capacity, SCVMM also provides flexibility in terms of automating the configuration of these service deployments. That said, there is some room to tack on additional deployment, configuration, or validation automation onto these service deployments. For instance, let’s assume that you are deploying a three tier service which consists of an application, database, and front end tier (three VM’s). Once these three VM’s have been deployed, you would like to loop back around and check each for patch compliance, antivirus compliance, and any number of other items. There are many options available for achieving these post deployment configuration validations. In this post I will be exploring one of these options – Configuring a System Center Virtual Machine Manager Service Deployment to initiate an Orchestrator Runbook using a post-installation script.
In this post I will be covering the following items:
- Orchestrator configuration - rather how to gather the required data from Orchestrator
- Virtual Machine Manager Service Template configuration - configuring the post-installation script
- I will finally provide a screen shot demonstration of the process in action
I will not be detailing how to create Runbooks, Service Templates, etc. If you need information on these activates there is a ton of available IP on the web.
So on with the fun.
Orchestrator Configuration:
All we need on the Orchestrator side of the house is to configure the Runbooks as we would like. These runbooks can be configured to perform just about any task you would like to include in your post deployment routine. For the example being demonstrated here, I have a very simple Runbook verifying that the computer is powered up, running a few checks using PowerShell, and then sending an email off indicting that the deployment and all checks have been completed. The Initialize Data activity in this Runbook contains one parameter which will ultimately consume the name of the VM being created during the Virtual machine Manager Service deployment.
With our Runbook built, we will need three pieces of data from the Orchestrator environment.
- Orchestrator WebService Address:
- Runbook Unique ID:
- Initialize Data Parameter Unique ID:
The first bit of data is easy enough to find, but what about the two unique ID’s. While there are several ways to gather these ID's, if you have access to the Orchestrator database, a good and quick option is to query the DB directly for this data. I’ve taken this query from this blog and modified slightly for use here. Notice the lower functions being used here – those are important. Visit the source for more information on why.
Select
lower(POL.UniqueID) as RunbookID,
lower(CSM.UniqueID) as ParameterID,
CSM.value
From POLICIES POL
INNER JOIN OBJECTS OBJ on POL.UniqueID = OBJ.ParentID
LEFT OUTER JOIN CUSTOM_START_PARAMETERS CSM on OBJ.UniqueID = CSM.ParentID
Where POL.Name = '<Runbook Name>' and POL.deleted = 0 and CSM.UniqueID IS NOT NULL
And we have our data, which completes the Orchestrator requirements - save this data off for later use.
Virtual Machine Manage Configuration:
While I will not go into detail on how to configure each component of this solution in VMM, I will do my best to note where to find relevant information. There is going to be some assumption here that you are familiar with Virtual Machine Manager and Service Template Deployments.
The following items will be needed in VMM
- A PowerShell script which will start the Runbook, this script is placed into the custom library resource
- A custom library resource
- A Service Template that is deploying at least on virtual machine.
Here is a quick look at the script I am using for starting the Runbook. This script can be found here - MSDN: Start a Runbook. I have only modified the script to add a parameter which will take in the VM value, and also commented out any write-host functions. Notice the unique ID's from our Orchestrator Runbooks as well as the Web Service location has been inserted into the appropriate spots within the script. Once this script has been configured, it will be placed in the SCVMM custom library resource.
Click image for better view:
Here we see examples of my custom library resource with the necessary PowerShell script. For more information on creating a custom library resource visit this article.
From within the service template designer, we have a simple Service Template deploying one VM. More information on creating Service Templates - TechNet Article.
After right clicking the service template and selecting properties, we can begin to configure this service template for the execution of the Orchestrator Runbook.
Click on Application Configuration.
Add a ‘Script to Application Profile’ to the Application Configuration.
Configure the Script as seen below:
- Script Deployment Type: Post-Install
- Executable program: %WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
- Parameters: -Command “& {.\startrb.ps1 @computername@ }”
- Select a Script resource package which is the custom library resource examined earlier
- Select a Run As account: will need access to initiate Orchestrator Runbooks
So let’s step and further examine what was just configured. We have specified here that we would like to execute a script after the service deployment has completed (post VM creation). We have specified that the command we will be running is PowerShell.exe and then provided some parameters to that command. Included in these parameters is startrb.ps1 which in this case is the name of the script that was placed in the custom resource package. We also have a parameter of @computerName@ - what is this little gem? As it turns out there are some understood variables that can be used during System Center Virtual Machine Manager Service deployments. This one maps back to the name of the VM created during the deployment. For a listing of other available variables check out this cloud builder blog. Finally we can see that the script resource package which contains the script is specified so that that call of .\startrb.ps1 will work.
So in essence we are executing 'powershell.exe –Command startrb.ps1 @computerName@ ' which makes allot of sense.
Let this baby fly:
With the configuration complete I will start a service deployment.
Click on any image for a better look.
Here we can see the name of the VM that is being created as part of this service TWOSCORCH03.TWOLAB.COM
After some time the deployment will complete.
We can then see that the Orchestrator Runbook as identified in the Post-Install script was executed at just about this same time. I've enabled Activity-specific Published Data logging on this Runbook so that we can visually inspect that the proper computer name was provided to the Runbook as parameter data.
And finally, because we end our Runbook with a send email activity, we have a nice indicator that not only has our service deployment completed, but that the associated virtual machine's have cleared all post deployment task and are ready for use.
Wrap Up:
So quite a few steps here, but once configured I have found this to be a very elegant solution for using System Center Virtual Machine manager to kick off post VM deployment tasks. As with many of my blog postings, the example demonstrated here (basically sending an email), is not the limitation of the solution. The only limitation is your creativity in automation – so happy automating.
Twitter Feed Subscription Button is at the right of the page – click it…