😀

Azure Automation でパブリックプレビューの Azure CLI 実行を試してみた

に公開

現時点ではパブリックプレビューなのですが、Azure Automation で Azure CLI が実行できるようになったのでやってみました。

検証用 Azure Automation を作成

Azure Automation を作って、マネージド ID を有効にして、リソースグループに共同作成者ロールを割り当てて、検証用のランブックを作成します。

bash
prefix=mnrauto
region=japaneast

az group create \
  --name ${prefix}-rg \
  --location $region

az automation account create \
  --automation-account-name ${prefix} \
  --resource-group ${prefix}-rg \
  --sku Free

az resource update \
  --ids $(az automation account show \
  --automation-account-name ${prefix} \
  --resource-group ${prefix}-rg \
  --query id \
  --output tsv) \
  --set "identity.type=systemassigned"

az role assignment create \
  --assignee $(az automation account show \
  --automation-account-name ${prefix} \
  --resource-group ${prefix}-rg \
  --query identity.principalId \
  --output tsv) \
  --scope $(az group show \
  --name ${prefix}-rg \
  --query id \
  --output tsv) \
  --role "Contributor"

resourceid=$(az automation account show \
  --automation-account-name ${prefix} \
  --resource-group ${prefix}-rg \
  --query id \
  --output tsv)

az rest \
  --method put \
  --url "https://management.azure.com${resourceid}/runbooks/${prefix}-test?api-version=2023-05-15-preview" \
  --body '{ 
  "properties": { 
        "runbookType": "PowerShell72"
    }, 
   "location": "japaneast"
}'

Runbook に Azure CLI コードを追加

azure-automation-cli-in-runbook-01.png

Runbook の実行結果

azure-automation-cli-in-runbook-02.png

参考

https://azure.microsoft.com/ja-jp/updates/azure-automation-runtime-environment-azurecli-support/

https://learn.microsoft.com/en-us/azure/automation/quickstart-cli-support-powershell-runbook-runtime-environment?tabs=create-runtime-env-portal%2Ccreate-runbook-rest

Discussion