1. Executing runbooks on on-premises servers using Hybrid Runbook Worker

    TypeScript

    If you are looking to execute runbooks on on-premises servers using a Hybrid Runbook Worker in Azure, you would need to set up a few key components in Azure Automation. The primary resources you need are an Automation Account, a Runbook, and Hybrid Runbook Worker Group configurations. The following Pulumi program in TypeScript demonstrates how you might set up these resources.

    1. Automation Account: This is the central component where runbooks are stored and managed.
    2. Runbook: The automation script or sequence of tasks that you wish to execute on your on-premises servers.
    3. Hybrid Runbook Worker Group: This defines a group of on-premises machines as workers that can execute the runbooks you've defined.

    Here's a Pulumi program that sets up these resources:

    import * as azureNative from "@pulumi/azure-native"; // Create an Azure Automation Account const automationAccount = new azureNative.automation.AutomationAccount("myAutomationAccount", { resourceGroupName: "myResourceGroup", // Location is required for automation account and should be same as your resource group. location: "East US", // The SKU name can either be Free, Basic, Standard; based on the scale needed. sku: { name: "Basic", }, }); // Create the Hybrid Runbook Worker Group const hybridRunbookWorkerGroup = new azureNative.automation.HybridRunbookWorkerGroup("myHybridRunbookWorkerGroup", { automationAccountName: automationAccount.name, resourceGroupName: "myResourceGroup", hybridRunbookWorkerGroupName: "myHybridWorkerGroup", // Credential name is necessary to authenticate against your on-premises environment credential: { name: "myCredentialName", // Replace with your credential name created in the Automation Account. }, }); // Create a Runbook const runbook = new azureNative.automation.Runbook("myRunbook", { automationAccountName: automationAccount.name, resourceGroupName: "myResourceGroup", location: "East US", runbookType: "PowerShellWorkflow", // Specify the type of runbook, e.g., PowerShellWorkflow, PowerShell, etc. draft: { draftContentLink: { uri: "https://mycontentlink.example.com/runbook.ps1", // Content links should point to the location of your runbook's code. // This could be a link to GitHub, Azure Blob Storage, or any other accessible URI. } }, }); // Output the Automation Account and Runbook details export const automationAccountId = automationAccount.id; export const runbookId = runbook.id; export const hybridRunbookWorkerGroupId = hybridRunbookWorkerGroup.id;

    In this program:

    • You require the azure-native package to create resources in Azure through Pulumi.
    • You create an AutomationAccount, specifying the resource group and the location that it should exist in, along with the SKU.
    • Then, you create a HybridRunbookWorkerGroup within your Automation Account.
    • After the Hybrid Runbook Worker Group is created, you define a Runbook also within your Automation Account.
    • The draft section of the Runbook defines where the actual runbook script is located; you need to replace the uri property with the actual location of your runbook code/script.
    • Finally, you export the IDs of the created resources so you can reference them as needed, which is particularly useful if your runbook needs to interact with other services or Pulumi stacks.