現時点ではパブリックプレビューなのですが、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 コードを追加
Runbook の実行結果
参考