How to run SSH Command on fresh Linux VM System Center Orchestrator
Here is a scenario:
Create a self-service to get a Linux machine based on VM template. While automating the process getting troubles to get the IP address of this fresh created VM, since it's configured to get IP address from IP Pool.
And you want to run SSH script to generalize the machine since there is software installed in this template.
So as a work around, the following Runbook is created:
Let’s start with the process:
Initialize Data
I added the following parameters for my client to choose a VM name and the Cloud that he wants to use.
(In your real environment you might mention different parameters, but for the purpose of the demonstration these are enough)
I will skip the next two activities since it should be easy to create a machine from template and start it.
Get VM
I added a filter to get the VM Name from published data as it’s shown in the following figure:
Query Database
SCVMM stores the assigned IP address in its SQL database in tbl_NetMan_AllocatedIPAddress table, but they are stored as varbinary(16) data type. So I can get the VM ID from that table to mention it in the PowerShell script to get the IP.
select ID from VirtualManagerDB.dbo.tbl_NetMan_AllocatedIPAddress where AssignedToObjectName = ‘{VM Name from “Get VM”}’
Run VMM PowerShell script
So now we have the ID of the created VM and we want to its IP using the Get-SCIPAddress
$var1 = Get-SCIPAddress -ID “{Full Line as a string with fileds separated by ‘;’ “from Query Database”}”
$var2 = $var1.address
Run SSH Command
Now we are able to mention the new created VM in the computer field using the published data:
{Output Variable 01 from "Run VMM PowerShell Script"}
And run the command you want.
There are always different ways to accomplish the same task but I found this is the best way to run you command on the VM directly without any extra actions, then the email is a luxury addition to make sure that the command has been successfully ran.