AcloudA

Introducing Azure Automation

Posted by Nicolas Prigent on December 19, 2017
No ratings yet.

Microsoft Azure Automation Logo

Automating every single task is one of the biggest challenges for every SysAdmin. Either you work on-premise or with Azure, you must automate most of your day-to-day task in order to save your time. In this article, I would like to introduce Azure Automation which is a software as a service (SaaS) application and a wonderful tool in order to automate repeated tasks. Nowadays, every SysAdmin should try to keep its IT infrastructure up and running.

If you have experience with automation workflow software like System Center Orchestrator or Service Management Automation (SMA), then you will be happy because Azure Automation is very similar. Azure Automation uses Runbooks. A runbook is a set of tasks that perform one or many actions automatically. For example, you can create a runbook that will:

Azure Runbooks are based on Windows PowerShell so you can use them to perform all your tasks by importing PowerShell modules, or calling another Runbook. If you don’t have PowerShell skills, you can use a graphical editor which lets you create graphical runbook. I will describe both options in this article.

Orchestrator, SMA or Azure Automation?

Depending if you work on-premise or not, you will use one of these following automation software:

SMA is part of Microsoft Azure Pack and will be used locally for your private cloud. SMA uses PowerShell and PowerShell Workflow but does not support graphical runbooks.

Orchestrator is focused on on-premises resources. SCO has a graphical interface in order to create your Runbooks. You don’t need scripting skills because SCO uses activities from “Integration Packs” which are packages built specifically for Orchestrator.

Finally, Azure Automation is what you need if you work with Azure. Let’s see how it works.

Architecture Overview

Runbooks in Azure Automation cannot access resources in your on-premise environment. If you want to use Azure Automation to run specific action in your on-premises environment, then the Hybrid Runbook Worker (HRW) feature is what you need to implement. Azure Automation allows you to run Runbooks directly on the computer hosting the HRW role but Runbooks are stored and managed in Azure Automation.

Note that you can use DSC Configuration to manage your Azure Virtual Machines and on-premise machines. The only pre-requisite is to create an Outbound Firewall rule from your on-premise machine to Azure DSC Pull Server, communicating over TCP port 443.

Below is the Automation Architecture from Microsoft Website:

Microsoft Azure Automation Architecture - Sheme

How to Use Azure Automation?

To get started using Azure Automation, you must create your first Automation account. What is an Azure Automation Account? An Automation account is separate from the account you use to sign in to the Azure portal. Azure Automation allows you to automate tasks against resources in Azure. So your Runbook must be able to perform specific actions, and it will use this Azure Automation Account which must have permissions to securely access the resources. Let’s see how to create the Azure Automation Account.

Go to the Azure portal, select “Automation Accounts”:

Microsoft Azure Portal - Automation Account

Click “Create Automation Accounts

Microsoft Azure Portal - Create Automation Accounts

Now, fill out the following fields:

  • Enter the Name of your Automation Account
  • Select your Azure Subscription
  • Select a Resource Group or create a new one
  • Select the location
  • Click “Yes” to create an Azure Run As Account. This Run As account will be used in your Runbooks.

And click “Create” to add your Automation Account:

Microsoft Azure Portal - Add Automation Account - Details

Now, I can create my first Runbook but I have to choose which type of Runbook I want to create. Azure Automation supports many types of Runbooks:

  • Graphical: Based on Windows PowerShell and created in the graphical editor in Azure portal.
  • Graphical PowerShell Workflow: Based on Windows PowerShell Workflow and created in graphical editor in Azure portal
  • PowerShell: Based on Windows PowerShell and created in text format
  • PowerShell Workflow: Based on Windows PowerShell Workflow and created in text format
  • Python: Based on Python and created in text format

Let’s see how it works. Go to “Runbooks”, click “Add Runbook”, then either create a new Runbook or import an existing Runbook. Here I create a new Runbook based on Windows PowerShell.

Microsoft Azure Portal - Runbooks - Add Runbook

Once the Runbook is created, click “Edit” in order to modify the Runbook which is actually empty.

Microsoft Azure Portal - Runbook - Overview - Edit

In this Runbook, I just want to list all my Azure Virtual Machines. You can create your script from your ISE and copy/paste your code into the Runbook.

Edit PowerShell Runbook

Notice the library on the left panel. This library can be used to add cmdlets, runbooks, and assets directly to your runbook. It can be very useful if you don’t remember the name of some cmdlets or just to include another Runbook. You also can add credentials from “Assets” tab. Click “” and “Add to canvas”:

Get-AzureRmVm - Add to canvas

Once your runbook is ready, you can go to the test pane in order to check if it works or not. So click “Test pane”:

Edit PowerShell Runbook - Test plane

Now, you can test the runbook by clicking the “Start” button. The job status starts as Queued indicating that it is waiting for a runbook worker in the cloud to come available. It will then move to Running and Completed status.

Runbook - Completed

The runbook is actually in a draft mode. We must publish it before we can use it in production. After publishing your runbook, you can schedule it or export it.

Publish Runbook

How to Import Runbooks?

If you don’t have scripting skills, note that you can import several Runbooks created by the community. You also can import graphical Runbooks. The Azure Automation Runbook Gallery pulls Runbook content from the PowerShell Gallery in addition to Script Center. So to import an existing Runbook, you can click “Browse Gallery”:

Automation Account - Runbooks - Browse gallery

When you import a Runbook, an entry will be added to your Runbooks repository:

Start Azure Classic VMs - Import

Azure Automation with PowerShell

All the previous steps can be performed with Windows PowerShell. For example, I can get all the Runbooks with the Get-AzureRmAutomationRunbook cmdlet:

Microsoft Windows PowerShell - Get-AzureRmAutomationRunbook

Of course, I can create a Runbook using the New-AzureRMAutomationRunbook cmdlet:

Microsoft Windows PowerShell - New-AzureRmAutomationRunbook

Finally, if I want to publish a Runbook, I must use the Publish-AzureRmAutomationRunbook cmdlet to publish a Runbook with Windows PowerShell. The following commands show how to publish a Runbook:

Microsoft Windows PowerShell - Publish-AzureRmAutomationRunbook

Graphical Runbooks

First, you must create a Graphical Runbook. Once the Runbook is created, edit the runbook and Azure Automation will help you to build your first graphical runbook. Graphical Runbooks are different than Orchestrator Runbooks because SCO uses activities instead of PowerShell. Here, we must select an item from the library in the left pane and insert it to build the Runbook.

Edit Graphical Runbook - Build

Once your Runbook is built with all the steps, we must configure properties into the right panel. Select an item, configure properties from the right panel.

Edit Graphical Runbook - Configure

When it’s done, simply click “Start” and Azure Automation will run all the steps inside the Runbook.

Conclusion

Thanks to Azure Automation, you can create PowerShell Runbooks or Graphical Runbooks in order to easily automate your day-to-day tasks. You can now start building any type of Runbook which can perform any action you need.

Azure is not free, so if you need more information about pricing, you can read this article: https://azure.microsoft.com/en-us/pricing/details/automation/

Thanks for reading!

 

Related materials:

Views All Time
2
Views Today
8
Return to all posts

Install updates in WIM files to accelerate OS deployment
Amazon Has Mysterious Ways: AWS Announces the Secret Region

Please rate this

The following two tabs change content below.

Leave a Reply

You must be logged in to post a comment.