Archive

Posts Tagged ‘Automation’

Automating the deployment of Hyper-V hosts with VMM 2016 with Baremetal deployment

To deploy a new Hyper-V host from bare metal, the following simple steps are carried out by System Center 2016 Virtual Machine Manager (VMM) :

  1. VMM Discovers the physical computer through out-of-band management (BMC)
  2. VMM Installs an OS image on the physical computer using a previously created physical computer profile.
  3. VMM Enables the Hyper-V role on the physical computer.
  4. VMM Brings the computer under VMM management as a managed Hyper-V host.

Now in order for that to happen, let’s see what pre-requisites you are required to provide first:

  1. DNS and Active Directory
    Create DNS entries and Active Directory account for the machine names.
  2. BIOS

    a. Set up the BIOS on the machine to support virtualization: Configuring the BIOS boot order to boot from (PXE)-enabled network adapter as the first device.
    b. Configure the BMC settings. Configure the logon credentials and IP address settings for the BMC on each computer.
  3. Add a PXE server environment: A PXE server integrated to VMM is required for Bare Metal deployment.
  4. Add resources to VMM library: Add a generalized virtual hard disk with an suitable OS to use as the base image, and driver files that will be added to the during installation of the OS.
  5. Create a Run As account. In VMM create a Run As Account with permissions to access the BMC.
  6. Create Physical Computer profiles: In the VMM library, create one or more physical computer profiles. These profiles include configuration settings, such as the location of the operating system image, and hardware and OS settings.


Now let’s have a look on the step by step to provision a Hyper-V host using Baremetal Deployment:

  1. Click Fabric > Servers > Home > Add > Add Resources > Hyper-V Hosts and Clusters.
  2. In the Add Resource Wizard > Resource location, select Physical computers to be provisioned as virtual machine hosts.
  3. In Credentials and Protocol select the Run As account with permissions to access the BMC. In the Protocol list, click the out-of-band management protocol that your BMCs use. If you want to use Data Center Management Interface (DCMI), click Intelligent Platform Management Interface (IPMI). Although DCMI 1.0 is not listed, it is supported. Make sure the correct port is selected.
  4. In Discovery Scope, enter the single IP address, the IP subnet, or the IP address range that includes the IP addresses of the BMCs

Note:

  • If you specify a single IP address, when you click Next, the computer is restarted.
  • If you specify an IP address range, when you click Next, information about the computer is displayed, and you can confirm that you specified the computer that you meant to.

4a. If you specified an IP subnet or IP address range the Target Resources page appears. Select the BMCs you want to provision as Hyper-V hosts.

  1. In Provisioning Options, click a host group for new Hyper-V hosts. Select the physical computer profile you want to apply.
  2. In Deployment Customization, provide information for each computer that you want to provision as a Hyper-V host:

Note: To remove a BMC from the list, select it and then click Remove.

For each BMC IP address in the list:

    • Click the BMC IP address and specify a unique computer name, without wildcard characters.
    • Select or clear Skip Active Directory for this computer name. The Active Directory check prevents deployment if the computer account already exists.
    • For each BMC IP address in the list:
    • Click on the Network Adapter (on the left) to modify the configuration, or fill in more information. You can specify the MAC address of the management NIC (not the BMC) and static IP settings for this network adapter.
    • To specify an IP address select a logical network and an IP subnet if applicable. If the selected IP subnet includes IP address pool, you can check Obtain an IP address corresponding to the selected subnet. Otherwise, type an IP address that’s within the logical network or its subnet.
    • Configure the adapter settings for each network adapter. You must specify any information that is missing for the adapters.
    • When all information for the listed BMC are completed, click Next.
  1. In Summary, confirm the settings, and then click Finish to deploy the new Hyper-V hosts and bring them under VMM management.

Make sure that all steps in the job have a status of Completed.

  1. To confirm that the host was added click Fabric > Servers > All Hosts > host group, and verify that the new Hyper-V host appears in the group.

 

Note: Nano Server is not a supported OS for infrastructure-related roles like Hyper-V. I recommend that you use Windows 2016 Core Server version

Azure Automation: Calling a PowerShell from a WebApp

I am working on a project that requires an Azure PowerShell to be called from a WebApp. Without entering in the details of the app, I faced a problem when writing the PowerShell script when it came to the authentication and running the PowerShell script from the Azure Automation portal is not my scenario.

webhook-overview-image

Automation: The figure shows an External App calling a Microsoft Azure Webhook to starts a runbook

Before I start, let’s have a look on the authentication Methods. The following table summarizes the different authentication methods for each environment supported by Azure Automation and the article describing how to setup authentication for your runbooks.

Method Environment Article
Azure AD User Account Azure Resource Manager and Azure Service Management Authenticate Runbooks with Azure AD User account
Azure AD Service Principal object Azure Resource Manager Authenticate Runbooks with Azure Run As account
Windows Authentication On-Premises Datacenter Authenticate Runbooks for Hybrid Runbook Workers
AWS Credentials Amazon Web Services Authenticate Runbooks with Amazon Web Services (AWS)

So, what methods I found to start the PowerShell from my WebApp?

  • Option 1: Webapp calling a PowerShell Azure RM Automation Runbook.
  • Option 2: Webapp calling an Azure Automation webhooks. Great way of doing it. A webhook allows you to start a particular runbook in Azure Automation through a single HTTP request. The webhook would allow external services such as my custom application to start runbooks.
  • Option 3: Webapp calling a PowerShell script. The issue here becomes the authentication.

 

Let’s start with Option 1. I will discuss the other options in the next posts

 

Option 1: Webapp calling a PowerShell Azure RM Automation Runbook

You can use PowerShell Workflow (recommended as you can use parallel processing to perform multiple actions in parallel) or PowerShell Script. More info here.

Note: You can’t convert runbooks from one type to another.

Create an Azure automation account

1.1.         Log in to the Azure portal.

1.2.         Click New > Management > Automation Account

1.3.         In the Add Automation Account blade, configure your Automation Account details (e.g. Name)

1.4.         From your automation account, click the Assets part to open the Assets blade to create a new credential.

1.5.         Click the Credentials part to open the Credentials blade.

1.6.         Click Add a credential at the top of the blade.

1.7.         Complete the form and click Create to save the new credential. For more info see Credential assets in Azure Automation

 

Create a PowerShell script/workflow with the commands required for your solution (for example: get a list of VM’s)

$cred = Get-AutomationPSCredential –Name “Replace with the Crendential NAME”

Add-AzureRMAccount –Credential $cred Select-AzureSubscription –SubscriptionName “replace your Subscription NAME”

Get-AzureVM

 

Create an Azure Automation Runbook

1.8.    In the Azure Portal, click on Automation Accounts and select the Automation account you created previously

1.9.    Click on the Runbooks tile to open the list of runbooks.

1.10.    Click on the Add a runbook button and then Import.

1.11.    Click Runbook file to select the file to import

1.12.    If the Name field is enabled, then you have the option to change it. The runbook name must start with a letter and can have letters, numbers, underscores, and dashes.

1.13.    Select a runbook type taking into account the restrictions listed above.

1.14.    The new runbook will appear in the list of runbooks for the Automation Account.

1.15.    You must publish the runbook before you can run it.

Alternatively, to import a runbook from a script file with Windows PowerShell:

$AutomationAcct = “Your Automation Account Name”

$runbookName = “TestRunbook”

$scriptPath = “c:\MyRunbooks\TestRunbook.ps1”

Set-AzureAutomationRunbookDefinition -AutomationAccountName $AutomationAcct -Name $runbookName -Path $ scriptPath -Overwrite

Publish-AzureAutomationRunbook -AutomationAccountName $AutomationAcct –Name $runbookName

 

Create an ASP.NET website which will call a PowerShell command.

The Webapp should call the following PowerShell:

Start-AzureAutomationRunbook –AutomationAccountName “replace with your Automation Account NAME created in step 1.3″ –Name ” replace with your runbook name. for eample:MyGetVMRunbook ”

For more info, click here

Next Post: Option 2 and 3….

Categories: Cloud, Microsoft Tags: , ,