<<Sharing the solution for the benefit of other community members who might be looking for an answer to similar issue>>
Steps involved to deploy Arc extension HRW (hybrid runbook worker) are:
- To create HRW group
- To confirm HRW group creation
- To generate a GUID and create HRW URI
- To confirm HRW creation make a get call
- To retrieve Automation Account Hybrid Service URL
- To create the extension
Script:
$subscriptionId = "" #Automation Account sub id
$automationAccountName = "" #Automation account name
$resourceGroupName = "" #Automation Account RG
$token = (get-azaccesstoken).Token
$hybridRunbookWorkerGroupName = "" # HRWG group to be created
$ARCSubscriptionId = "" #ARC machine sub id
$ARCresourceGroupName = "" #ARC machine RG
$ARCmachineName = "" #ARC machine name
$ARCMachinelocation = "" # ARC Machine location
$ARCServerResourceId = "/subscriptions/$ARCSubscriptionId/resourceGroups/$ARCresourceGroupName/providers/Microsoft.HybridCompute/machines/$ARCmachineName"
#Update all the above varialbles before using the below script
#Create HRW Group URI
$headers = @{Authorization = "Bearer $token"}
$createHRWGroupuri = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Automation/automationAccounts/$automationAccountName/hybridRunbookWorkerGroups/$($hybridRunbookWorkerGroupName)?api-version=2021-06-22"
$contentType = "application/json"
$body = @{} | ConvertTo-Json
$response = Invoke-WebRequest -Uri $createHRWGroupuri -Method PUT -Headers $headers -Body $body -ContentType $contentType
$response.Content
#To Confirm HRW Group Creation
(Invoke-WebRequest -Uri $createHRWGroupuri -Method Get -Headers $headers).Content
#Generate HRW id
$hrwId = New-Guid
#Create HRW URI
$createHRWuri = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Automation/automationAccounts/$automationAccountName/hybridRunbookWorkerGroups/$hybridRunbookWorkerGroupName/hybridRunbookWorkers/$($hrwId)?api-version=2021-06-22"
$body = @"
{
"properties":{"vmResourceId": "$ARCServerResourceId"}
}
"@
$response = Invoke-WebRequest -Uri $createHRWuri -Method PUT -Headers $headers -Body $body -ContentType $contentType
$response.Content
#To Confirm HRW Creation make a get
(Invoke-WebRequest -Uri $createHRWuri -Method Get -Headers $headers).Content
##### HRW is not Visible yet in the portal#####
#Retrieve Automation Account Hybrid URL
$automationAccountInfouri = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Automation/automationAccounts/$($automationAccountName)?api-version=2021-06-22"
$automationHybridServiceUrl = ((Invoke-WebRequest -Uri $automationAccountInfouri -Method Get -Headers $headers).Content) | ConvertFrom-Json | Select -expand properties | Select -expand automationHybridServiceUrl
$automationHybridServiceUrl
$CreateARCExtensionUri = "https://management.azure.com/subscriptions/$ARCSubscriptionId/resourceGroups/$ARCresourceGroupName/providers/Microsoft.HybridCompute/machines/$ARCmachineName/extensions/HybridWorkerExtension?api-version=2021-05-20"
$CreateARCExtensionBody = @{
'location' = $($ARCMachinelocation)
'properties' = @{
'publisher' = 'Microsoft.Azure.Automation.HybridWorker'
'type' = 'HybridWorkerForWindows'
'typeHandlerVersion' = '0.1.0.18'
'autoUpgradeMinorVersion' = $false
'enableAutomaticUpgrade' = $false
'settings' = @{
'AutomationAccountURL' = $automationHybridServiceUrl
}
}
} | ConvertTo-Json -depth 2
#Create the Extension
Invoke-WebRequest -Uri $CreateARCExtensionUri -Method PUT -Headers $headers -Body $CreateARCExtensionBody -ContentType $contentType
Illustration:
Hi, I created a MS Case for this. Today I received an update with code on how to deploy via API calls. So my issue is solved.
Hi @Peter Smit ,
Glad to know that the issue is resolved. Can you share the resolution steps here so it might help other community members who might look for an answer on the similar issue?
Hi @Peter Smit ,
For the benefit of other community members who might be looking for an answer to similar issue, I have shared the solution provided via MS case in the below answer section.
Also, I have got an update from Azure Automation product team that in couple of days we will be adding another section in this Azure document that explains the steps to deploy the extension based HRW through REST API.
Sign in to comment