Service Management Automation is an IT process automation solution for Windows Azure Pack for Windows Server. It enables you to automate the creation, monitoring, and deployment of resources in your Windows Azure Pack environment.
This blog is meant for IT teams who are trying to migrate their traditional data center Orchestrator runbook to SMA. I am targeting simple runbooks here which contains single .Net activity (the PowerShell script inside the .net script activity can be complex though 🙂 ), something like shown below.
Before jumping into code details of Orchestrator runbook and SMA runbook, Please make sure you have a working Orchestrator and SMA environment. Below are the main requirements for this scenario
1. Prepare SMA environment
2. System Center Orchestrator 2012 RTM or above
Follow this link to prepare Orchestrator environment.
3. Windows Azure Pack
Follow this link for more details of WAP.
4. System Center Virtual Machine Manager 2012 RTM or above.
Follow this link to prepare SCVMM environment. We need VMM as we are using sample Orchestrator runbook which changes the memory or CPU count of Virtual machines using VMM.
For SMA to Orchestrator integration i.e. invoking a SMA runbook from Orchestrator and Orchestrator runbook from SMA, please refer this article written by Chris Sanders.
We will achieve below in this blog
1. Creating a sample Orchestrator Runbook. (ChangeVM)
2. Step by step process of converting Orchestrator Runbook to SMA (Invoke-ChangeVM)
You can use your already created runbooks also for step 1. You can directly jump to Step 2 to see the conversion steps J
These are the requirements for this scenario:
- VMM Server and SMA Server should be in same domain.
- VMM server must be reachable from SMA server (Connectivity). Please follow below steps to test.
· Ping the VMM Server and confirm it is working. Please refer below image.
· Create PSSession of VMM Server and confirm it is working. Please refer below image.
- ExecutionPolicy should be set as ‘RemoteSigned’ on both SMA and VMM server.
- The VM needs to be in either Power Off or Stored State mode before SCVMM can perform the specified hardware changes.
- Given Memory value in ChangeVM runbook should be in increments of 2MB. Odd values are not accepted while assigning Memory.
Step 1:- Creating Sample Orchestrator Runbook (ChangeVM)
You can follow this free ebook written by Andreas Rynes on Designing Orchestrator runbooks. This ebook provides a framework for designing Runbooks and IT process automation to help the IT Pro get the most out of their System Center 2012 Orchestrator implementation and help them to utilize Orchestrator in a very modular approach, focusing on small, focused pieces of automation.
‘Change VM’ Orchestrator Runbook is responsible for changing configuration of an existing VM (Memory). The runbook accepts below parameters:-
1. $VMAction – Action to be performed on existing VM e.g. IncreaseMemory, DecreaseMemory.
2. $VMValue – Value of Memory to be increased or decreased, VMValue should be in increments of 2MB
3. $VMMServerName – Name of the SCVMM Server.
4. $VMName – Name of the VM that needs to be configured.
This runbook creates remote session to SCVMM server and uses Set-VM cmdlet to set the memory. The values of VMName, VMMServerName, VMAction and VMValue will be read from ‘Initialize Data’ activity
The runbook script is pasted in below box:-
Step 2:- Converting Orchestrator Runbook into SMA Workflow (Invoke-ChangeVM)
This section contains all details of step by step process of converting the Orchestrator Runbook ‘ChangeVM’ into SMA workflow.
Following are the generalized steps that can be followed by any existing Orchestrator runbook that has to be converted into SMA workflow:-
1. Create an empty PowerShell Workflow container.
2. Add the existing PowerShell script inside Workflow container.
3. Convert the Initialize Data Parameters read by script, if any, to workflow parameters.
4. Add InlineScript activity inside the workflow after the parameters and move the code inside the InlineScript activity.
5. Reassign the parameters read in workflow inside InlineScript using ‘$Using:’ as the scope is different and parameters are not directly available.
6. If you are creating a PSSession inside the script, make sure you invoke the session with required credentials, if current SMA user is not having access to the remote machine.
7. Import the Workflow in SMA server.
8. Run the Workflow and verify the output.
Detail of each step is shown with the help of example in below section of this document.
This example will show the steps followed while converting the Component Runbook ‘Change VM’ to SMA Runbook ‘Invoke-ChangeVM’.
1. Create an empty PowerShell Workflow container named ‘Invoke-ChangeVM’ as shown in image below.
2. Add Orchestrator .Net Script PowerShell code inside the PowerShell workflow as shown in image below.
3. Convert Input Parameters from Initialize Data Activity to SMA Workflow Parameters as shown in lines 3-11 below. Two more parameters ‘UserName’ and ‘Password’ are added in this workflow which are used while creating session to VMM server.
4. Add the whole code written in workflow except parameters to InlineScript as shown in line 13 below.
The InlineScript activity runs commands in a shared Windows PowerShell session. You can include it in a workflow to run commands that share data and commands that are not otherwise valid in a workflow.
The InlineScript script block can include all valid Windows PowerShell commands and expressions. Because the commands and expressions in an InlineScript script block run in the same session, they share all state and data, including imported modules and the values of variables. More details for InlineScript can be found at http://technet.microsoft.com/en-us/library/jj649082.aspx
5. Reassign the parameter values inside InlineScript using ‘$Using:’ keyword as shown in lines 15-19 below. PowerShell workflow parameters are not available inside InlineScript scope. More details on using variables in PowerShell workflows can be read at http://technet.microsoft.com/en-us/library/jj574187.aspx
6. Add credentials while creating PSSession to remote SCVMM server as current logged in user in SMA server might not have access to remote VMM server as shown in lines 29-32 below. This step is optional incase the logged in user of SMA has got required access on SCVMM server.
7. The final SMA Workflow script will look like below
8. Import the runbook on SMA server
9. Run the SMA workflow. Enter Parameters values.
10. The output of the SMA Runbook can be seen in Output pane.
I hope the above content will be useful to you and has given you a first step to start working on converting traditional Orchestrator runbooks to SMA runbooks.
In my next blog, I will discuss scenario on how you can move complex runbooks to SMA.
Till then, happy automating! 🙂