自訂指令碼延伸模組 2 版會在 Azure 虛擬機器 (VM) 上下載並執行指令碼。 此延伸模組對部署後設定、軟體安裝或其他任何設定或管理工作很實用。 您可以從 Azure 儲存體或其他可存取的網際網路位置下載指令碼,或是將指令碼提供給擴充功能執行階段。
自訂指令碼功能可以與 Azure Resource Manager 範本整合。 您也可以使用 Azure CLI、Azure PowerShell 或 Azure 虛擬機器 REST API 來執行它。
本文將說明如何從 Azure CLI 使用自訂指令碼延伸模組,以及如何使用 Azure Resource Manager 範本來執行此延伸模組。 本文也提供適用於 Linux 系統的疑難排解步驟。
自訂指令碼延伸模組有兩個版本:
- 1 版:Microsoft.OSTCExtensions.CustomScriptForLinux
- 2 版:Microsoft.Azure.Extensions.CustomScript
針對新的和現有的部署使用第 2 版。 新版本為簡易替換 (drop-in replacement)。 移轉與變更名稱和版本一樣簡單。 您不須變更延伸模組設定。
備註
試試 VM assist 快速診斷。 建議您執行 適用於 Windows 的 VM 協助 或 適用於 Linux 的 VM 協助。 這些腳本型診斷工具可協助您識別影響 Azure VM 客體代理程式和整體 VM 健康情況的常見問題。
先決條件
支援的 Linux 散發套件
| Publisher | 散發 | x64 | ARM64 |
|---|---|---|---|
| Alma Linux 社群 | 阿爾瑪Linux | 8.x+、9.x+ | 8.x+、9.x+ |
| Credativ | Debian | 10+ | 11.x+ |
| Kinvolk | Flatcar Linux | 3374.2.x+ | 3374.2.x+ |
| Microsoft | Azure Linux | 2.x | 2.x |
| openSUSE 專案 | openSUSE | 12.3+ | 不支援 |
| Oracle | Oracle Linux | 6.4+、7.x+、8.x+ | 不支援 |
| 紅帽 | Red Hat Enterprise Linux | 6.7+、7.x+、8.x+、9.x+、10.x+ | 8.6+、9.0+、10.x+ |
| CIQ | 洛基Linux | 9.x+ | 9.x+ |
| SUSE | SLES | 12.x+、15.x+ | 15.x SP4+ |
| Canonical | Ubuntu (LTS 版本) | 18.04+、20.04+、22.04+、24.04+ | 20.04+, 22.04+, 24.04+ |
指令碼位置
您可以將延伸模組設定為使用 Azure Blob 儲存體認證,以便能存取 Azure Blob 儲存體。 指令碼可以位於任何位置,前提是 VM 可以路由傳送至該端點 (例如,GitHub 或內部檔案伺服器)。
因特網連線能力
若要從外部 (例如從 GitHub 或 Azure 儲存體) 下載指令碼,您需要開啟其他防火牆或網路安全性群組 (NSG) 連接埠。 舉例來說,如果您的指令碼位於 Azure 儲存體,則可以允許使用 Azure NSG 適用於儲存體的服務標籤進行存取。
如果您的指令碼位於本機伺服器上,您可能仍需要開啟其他防火牆或 NSG 連接埠。
提示
- 此擴充功能的最高失敗率導因於指令碼中的語法錯誤。 確認指令碼執行無誤。 將更多的記錄放入指令碼,以便於更容易找到失敗問題。
- 撰寫具有等冪性的指令碼,這樣即使意外執行多次也不會導致系統變更。
- 確保在指令碼執行時,不需要使用者輸入。
- 指令碼可執行 90 分鐘。 任何過長的內容都會導致延伸模組佈建失敗。
- 請勿將重新開機置於指令碼內。 重新啟動會導致正在安裝的其他延伸模組發生問題,而且延伸模組在重新啟動後不會繼續運作。
- 如果您的指令碼在安裝應用程式和執行指令碼之前導致重新啟動,請使用 cron 工作或使用 DSC、Chef 或 Puppet 延伸模組等工具來排程重新啟動。
- 請勿執行導致 Azure Linux 代理程式停止或更新的指令碼。 它可能會讓延伸模組處於過渡的狀態,並導致逾時。
- 延伸模組只會執行一次指令碼。 如果您想要在每次開機時執行指令碼,則可以使用 cloud-init 映像,並使用 Scripts Per Boot 模組。 或者,您可以使用指令碼來建立 systemd 服務單位。
- 您只能將一個延伸模組版本套用至 VM。 若要執行第二個自訂指令碼,請使用新的設定來更新現有的延伸模組。 或者,您也可以移除自訂指令碼延伸模組,然後使用更新的指令碼來重新套用它。
- 如果您想要排程指令碼的執行時間,請使用延伸模組來建立 cron 工作。
- 當指令碼執行時,您只會從 Azure 入口網站或 CLI 中看到轉換中的延伸模組狀態。 如果您想要更頻繁地查看正在執行的指令碼的狀態更新,請建立自己的解決方案。
- 自訂指令碼延伸模組原生不支援 Proxy 伺服器。 不過,您可以在您的指令碼中使用支援 Proxy 伺服器的檔案傳輸工具,例如
Curl。 - 請注意指令碼或命令可能依賴的非預設目錄位置。 有邏輯可以處理此情況。
擴充功能結構描述
「自訂指令碼擴充功能」組態會指定指令碼位置和要執行命令等項目。 您可將此資訊儲存在設定檔中、在命令列中指定設定,或在 Azure Resource Manager 範本中指定設定。
您可將敏感性資料儲存在受保護的設定中,此設定會經過加密,並且只會在目標 VM 上解密。 當執行命令包含機密資料 (例如密碼) 時,受保護的組態會相當有用。 以下為範例:
{
"name": "config-app",
"type": "Extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2019-03-01",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', concat(variables('vmName'),copyindex()))]"
],
"tags": {
"displayName": "config-app"
},
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.1",
"autoUpgradeMinorVersion": true,
"settings": {
"skipDos2Unix":false,
"timestamp":123456789
},
"protectedSettings": {
"commandToExecute": "<command-to-execute>",
"script": "<base64-script-to-execute>",
"storageAccountName": "<storage-account-name>",
"storageAccountKey": "<storage-account-key>",
"fileUris": ["https://.."],
"managedIdentity" : "<managed-identity-identifier>"
}
}
}
備註
managedIdentity 屬性「不得」與 storageAccountName 或 storageAccountKey 屬性搭配使用。
屬性值
| 名稱 | 值或範例 | 數據類型 |
|---|---|---|
| apiVersion | 2019-03-01 |
date |
| 發行者 | Microsoft.Azure.Extensions |
字串 |
| 型別 | CustomScript |
字串 |
| typeHandlerVersion | 2.1 |
整數 (int) |
| fileUris | https://github.com/MyProject/Archive/MyPythonScript.py |
陣列 |
| commandToExecute | python MyPythonScript.py \<my-param1> |
字串 |
| 指令 | IyEvYmluL3NoCmVjaG8gIlVwZGF0aW5nIHBhY2thZ2VzIC4uLiIKYXB0IHVwZGF0ZQphcHQgdXBncmFkZSAteQo= |
字串 |
| skipDos2Unix | false |
boolean |
| 時間戳記 | 123456789 |
32 位元整數 |
| storageAccountName | examplestorageacct |
字串 |
| 存儲帳戶密鑰 | TmJK/1N3AbAZ3q/+hOXoi/l73zOqsaxXDhqa9Y83/v5UpXQp2DQIBuv2Tifp60cE/OaHsJZmQZ7teQfczQj8hg== |
字串 |
| managedIdentity |
{ }、{ "clientId": "00001111-aaaa-2222-bbbb-3333cccc4444" } 或 { "objectId": "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" } |
JSON 物件 |
屬性值詳細資料
| 房產 | 選擇性或必要 | 詳細資訊 |
|---|---|---|
| apiVersion | 不適用 | 您可以使用資源總管 或使用 Azure CLI 中的命令 az provider list -o json,尋找最新 API 版本。 |
| fileUris | 可選 | 要下載的 URL 或檔案。 |
| commandToExecute | 如果未設定 script,則為必要 |
要執行的進入點指令碼。 如果您的命令包含祕密 (例如密碼),請改用此屬性,而非 script。 |
| 指令 | 如果未設定 commandToExecute,則為必要 |
/bin/sh 執行的 Base64 編碼並選擇性使用 gzip 指令碼。 |
| skipDos2Unix | 可選 | 如果您想要略過指令碼型檔案 URL 或指令碼的 dos2unix 轉換,請將此值設定為 false。 |
| 時間戳記 | 可選 | 只在觸發重新執行指令碼的情況下,變更此值。 只要與先前的值不同,任何整數值都可接受。 |
| storageAccountName | 可選 | 儲存體帳戶的名稱。 如果您指定儲存體認證,則所有 fileUris 值都必須是 Azure Blob 的 URL。 |
| 存儲帳戶密鑰 | 可選 | 儲存體帳戶的存取金鑰。 |
| managedIdentity | 可選 | 用於下載檔案的受控識別。 值為 clientId (選用、字串),這是受控識別的用戶端識別碼,而 objectId (選用、字串),這是受控識別的物件識別碼。 |
公開設定會以純文字格式,傳送到執行指令碼所在的 VM。 受保護的設定會透過只有 Azure 和 VM 知道的金鑰加密。 設定會以傳送時的形式,儲存至 VM。 也就是說,如果設定經加密,會以加密形式儲存在 VM 上。 用來解密加密值的憑證會儲存在 VM 上。 此憑證也會用來在執行階段解密設定 (如有需要)。
使用公開設定可能有助於偵錯,但強烈建議您使用受保護的設定。
您可以在公用或受保護的設定中設定下列值。 延伸模組會拒絕任何在公用和受保護的設定中設定下列值的設定。
commandToExecutescriptfileUris
屬性:skipDos2Unix
舊版自訂指令碼延伸模組 Microsoft.OSTCExtensions.CustomScriptForLinux,會藉由將 \r\n 轉譯為 \n,自動將 DOS 檔案轉換為 UNIX 檔案。 這項轉譯仍存在,並預設為開啟。 這項轉換會根據下列任何準則,套用至從 fileUris 下載的所有檔案或指令碼設定:
- 副檔名為 .sh、.txt、.py 或 .pl。 該指令碼設定一律符合此準則,因為它會被假設是使用 /bin/sh 執行的指令碼。該指令碼設定會以 script.sh 的形式儲存在 VM 上。
- 檔案的開頭為
#!。
預設值為 false,表示「會」執行 dos2unix 轉換。 您可以將 skipDos2Unix 設定為 true,略過 dos2unix 轉換:
{
"fileUris": ["<url>"],
"commandToExecute": "<command-to-execute>",
"skipDos2Unix": true
}
屬性:指令碼
自訂指令碼延伸模組支援執行使用者定義的指令碼。 指令碼設定將 commandToExecute 和 fileUris 合併為單一設定。 您不須設定要從 Azure 儲存體或 GitHub Gist 下載的檔案,即可將指令碼編碼為設定。 您可以使用指令碼取代 commandToExecute 和 fileUris。
以下為部分需求:
- 指令碼必須採用 Base64 編碼。
- 指令碼可以選擇性地使用 gzip。
- 您可以在公用或受保護的設定中使用指令碼設定。
- 指令碼參數的資料大小上限為 256 KB。 如果指令碼超過此大小,則不會執行。
例如,下列指令碼儲存至檔案 /script.sh/:
#!/bin/sh
echo "Creating directories ..."
mkdir /data
chown user:user /data
mkdir /appdata
chown user:user /appdata
您可以取得以下命令的輸出,建構正確的自訂指令碼延伸模組指令碼設定:
cat script.sh | base64 -w0
{
"script": "IyEvYmluL3NoCmVjaG8gIlVwZGF0aW5nIHBhY2thZ2VzIC4uLiIKYXB0IHVwZGF0ZQphcHQgdXBncmFkZSAteQo="
}
大部分情況下,指令碼可選擇性使用 gzip 進一步縮減大小。 自訂指令碼延伸模組會自動偵測使用 gzip 壓縮。
cat script | gzip -9 | base64 -w 0
自訂指令碼延伸模組會使用以下演算法來執行指令碼:
- 宣告指令碼值的長度不超過 256 KB。
- Base64 將指令碼的值解碼。
- 「嘗試」對 Base64 解碼的值使用 gunzip。
- 將解碼 (並選擇性解壓縮) 的值寫入至磁碟:/var/lib/waagent/custom-script/#/script.sh。
- 使用
_/bin/sh -c /var/lib/waagent/custom-script/#/script.sh執行指令碼。
屬性:managedIdentity
備註
必須在受保護的設定中,才能指定此屬性。
自訂指令碼延伸模組 (2.1 版和更新版本) 支援受控識別,從 fileUris 設定中提供的 URL 下載檔案。 此方法可讓自訂指令碼延伸模組存取 Azure 儲存體私人 Blob 或容器,而不需要使用者傳遞共用存取簽章 (SAS) 權杖或儲存體帳戶金鑰之類的秘密。
若要使用這項功能,可將系統指派或使用者指派的身分識別,新增至預期執行自訂指令碼延伸模組的 VM 或虛擬機器擴展集。 然後將受控識別存取權授與 Azure 儲存體容器或 Blob。
若要在目標 VM 或虛擬機器擴展集上,使用系統指派的身分識別,請將 managedidentity 設定為空白 JSON 物件。
{
"fileUris": ["https://mystorage.blob.core.windows.net/privatecontainer/script1.sh"],
"commandToExecute": "sh script1.sh",
"managedIdentity" : {}
}
若要在目標 VM 或虛擬機器擴展集上,使用使用者指派的身分識別,請使用受控識別的用戶端識別碼或物件識別碼設定 managedidentity。
{
"fileUris": ["https://mystorage.blob.core.windows.net/privatecontainer/script1.sh"],
"commandToExecute": "sh script1.sh",
"managedIdentity" : { "clientId": "00001111-aaaa-2222-bbbb-3333cccc4444" }
}
{
"fileUris": ["https://mystorage.blob.core.windows.net/privatecontainer/script1.sh"],
"commandToExecute": "sh script1.sh",
"managedIdentity" : { "objectId": "aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb" }
}
備註
managedIdentity 屬性「不得」與 storageAccountName 或 storageAccountKey 屬性搭配使用。
範本部署
您可以使用 Azure Resource Manager 範本部署 Azure VM 延伸模組。 上一節詳述的 JSON 結構描述可以用於 Azure Resource Manager 範本,在部署範本期間執行自訂指令碼延伸模組。 您可以在 GitHub 找到包含自訂指令碼延伸模組的範例範本。
{
"name": "config-app",
"type": "extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2019-03-01",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', concat(variables('vmName'),copyindex()))]"
],
"tags": {
"displayName": "config-app"
},
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.1",
"autoUpgradeMinorVersion": true,
"settings": {
},
"protectedSettings": {
"commandToExecute": "sh hello.sh <param2>",
"fileUris": ["https://github.com/MyProject/Archive/hello.sh"
]
}
}
}
備註
這些屬性名稱會區分大小寫。 為了避免發生部署問題,請使用如下所示的名稱。
Azure CLI
您要使用 Azure CLI 來執行自訂指令碼延伸模組時,請建立一個或多個設定檔。 設定檔至少必須包含 commandToExecute。
az vm extension set 命令會參考設定檔:
az vm extension set \
--resource-group myResourceGroup \
--vm-name myVM --name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings ./script-config.json
或者,您也可以在命令中以 JSON 格式化字串的形式指定設定。 此方法可讓您在執行期間指定設定,而不需使用個別的設定檔。
az vm extension set \
--resource-group exttest \
--vm-name exttest \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--protected-settings '{"fileUris": ["https://raw.githubusercontent.com/Microsoft/dotnet-core-sample-templates/master/dotnet-core-music-linux/scripts/config-music.sh"],"commandToExecute": "./config-music.sh"}'
範例:含指令檔的公用設定
此範例會使用名為 script-config.json 的下列指令碼檔案:
{
"fileUris": ["https://raw.githubusercontent.com/Microsoft/dotnet-core-sample-templates/master/dotnet-core-music-linux/scripts/config-music.sh"],
"commandToExecute": "./config-music.sh"
}
使用您選擇的文字編輯器或使用下列 CLI 命令來建立指令碼檔案:
cat <<EOF > script-config.json { "fileUris": ["https://raw.githubusercontent.com/Microsoft/dotnet-core-sample-templates/master/dotnet-core-music-linux/scripts/config-music.sh"], "commandToExecute": "./config-music.sh" } EOF執行以下命令:
az vm extension set \ --resource-group myResourceGroup \ --vm-name myVM --name customScript \ --publisher Microsoft.Azure.Extensions \ --settings ./script-config.json
範例:不含指令檔的公用設定
此範例使用下列 JSON 格式的內容:
{
"commandToExecute": "apt-get -y update && apt-get install -y apache2"
}
執行以下命令:
az vm extension set \
--resource-group tim0329vmRG \
--vm-name tim0329vm --name customScript \
--publisher Microsoft.Azure.Extensions \
--settings '{"commandToExecute": "apt-get -y update && apt-get install -y apache2"}'
範例:公用且受保護的設定檔
使用公用設定檔來指定指令檔的 URI:
{
"fileUris": ["https://raw.githubusercontent.com/Microsoft/dotnet-core-sample-templates/master/dotnet-core-music-linux/scripts/config-music.sh"]
}
使用受保護的設定檔來指定要執行的命令:
{
"commandToExecute": "./config-music.sh"
}
使用您選擇的文字編輯器或使用下列 CLI 命令來建立公用設定檔:
cat <<EOF > script-config.json { "fileUris": ["https://raw.githubusercontent.com/Microsoft/dotnet-core-sample-templates/master/dotnet-core-music-linux/scripts/config-music.sh"] } EOF使用您選擇的文字編輯器或使用下列 CLI 命令來建立受保護的設定檔:
cat <<EOF > protected-config.json { "commandToExecute": "./config-music.sh" } EOF執行以下命令:
az vm extension set \ --resource-group myResourceGroup \ --vm-name myVM \ --name customScript \ --publisher Microsoft.Azure.Extensions \ --settings ./script-config.json \ --protected-settings ./protected-config.json
虛擬機器擴展集
如果您從 Azure 入口網站部署自訂指令碼延伸模組,就無法對於在儲存體帳戶中存取指令碼的 SAS 權杖控制該權杖的到期日。 初始部署可運作,但儲存體帳戶的 SAS 權杖到期時,任何後續擴充作業都失敗,因為自訂指令碼延伸模組無法再存取儲存體帳戶。
在虛擬機器擴展集上部署自訂指令碼延伸模組時,建議您使用 PowerShell、Azure CLI 或 Azure Resource Manager 範本。 如此一來,您可以選擇使用受控識別,或直接控制 SAS 權杖的到期日,以便只要您需要,即可存取儲存體帳戶中的指令碼。
故障排除
當「自訂指令碼擴充功能」執行時,會建立指令碼,或將指令碼下載到類似下列範例的目錄。 命令輸出也會儲存到這個目錄的 stdout 和 stderr 檔案中。
sudo ls -l /var/lib/waagent/custom-script/download/0/
若要進行疑難排解,請先檢查 Linux 代理程式記錄,確認延伸模組已執行:
sudo cat /var/log/waagent.log
尋找延伸模組執行。 它看起來會像:
2018/04/26 17:47:22.110231 INFO [Microsoft.Azure.Extensions.customScript-2.0.6] [Enable] current handler state is: notinstalled
2018/04/26 17:47:22.306407 INFO Event: name=Microsoft.Azure.Extensions.customScript, op=Download, message=Download succeeded, duration=167
2018/04/26 17:47:22.339958 INFO [Microsoft.Azure.Extensions.customScript-2.0.6] Initialize extension directory
2018/04/26 17:47:22.368293 INFO [Microsoft.Azure.Extensions.customScript-2.0.6] Update settings file: 0.settings
2018/04/26 17:47:22.394482 INFO [Microsoft.Azure.Extensions.customScript-2.0.6] Install extension [bin/custom-script-shim install]
2018/04/26 17:47:23.432774 INFO Event: name=Microsoft.Azure.Extensions.customScript, op=Install, message=Launch command succeeded: bin/custom-script-shim install, duration=1007
2018/04/26 17:47:23.476151 INFO [Microsoft.Azure.Extensions.customScript-2.0.6] Enable extension [bin/custom-script-shim enable]
2018/04/26 17:47:24.516444 INFO Event: name=Microsoft.Azure.Extensions.customScript, op=Enable, message=Launch command succeeded: bin/custom-sc
在上述輸出中:
-
Enable為命令開始執行的時間。 -
Download與從 Azure 下載自訂指令碼延伸模組套件有關,與fileUris中指定的指令檔無關。
「Azure 指令碼擴充功能」會產生一個記錄檔,位置如下:
sudo cat /var/log/azure/custom-script/handler.log
尋找個別執行。 它看起來會像:
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event=start
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event=pre-check
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="comparing seqnum" path=mrseq
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="seqnum saved" path=mrseq
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="reading configuration"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="read configuration"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="validating json schema"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="json schema valid"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="parsing configuration json"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="parsed configuration json"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="validating configuration logically"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="validated configuration"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="creating output directory" path=/var/lib/waagent/custom-script/download/0
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="created output directory"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 files=1
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 file=0 event="download start"
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 file=0 event="download complete" output=/var/lib/waagent/custom-script/download/0
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="executing command" output=/var/lib/waagent/custom-script/download/0
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="executing protected commandToExecute" output=/var/lib/waagent/custom-script/download/0
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event="executed command" output=/var/lib/waagent/custom-script/download/0
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event=enabled
time=2018-04-26T17:47:23Z version=v2.0.6/git@1008306-clean operation=enable seq=0 event=end
您可以在此發現:
- 啟動此記錄的
enable命令。 - 傳遞至延伸模組的設定。
- 下載檔案及其動作結果的延伸模組。
- 正在執行的命令和結果。
您也可以使用 Azure CLI 來擷取自訂指令碼延伸模組的執行狀態,包括以 commandToExecute 傳遞的實際引數:
az vm extension list -g myResourceGroup --vm-name myVM
輸出看起來會像下列文字:
[
{
"autoUpgradeMinorVersion": true,
"forceUpdateTag": null,
"id": "/subscriptions/subscriptionid/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/vmname/extensions/customscript",
"resourceGroup": "rgname",
"settings": {
"commandToExecute": "sh script.sh > ",
"fileUris": [
"https://catalogartifact.azureedge.net/publicartifacts/scripts/script.sh",
"https://catalogartifact.azureedge.net/publicartifacts/scripts/script.sh"
]
},
"tags": null,
"type": "Microsoft.Compute/virtualMachines/extensions",
"typeHandlerVersion": "2.0",
"virtualMachineExtensionType": "CustomScript"
},
{
"autoUpgradeMinorVersion": true,
"forceUpdateTag": null,
"id": "/subscriptions/subscriptionid/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/vmname/extensions/OmsAgentForLinux",
"instanceView": null,
"location": "eastus",
"name": "OmsAgentForLinux",
"protectedSettings": null,
"provisioningState": "Succeeded",
"publisher": "Microsoft.EnterpriseCloud.Monitoring",
"resourceGroup": "rgname",
"settings": {
"workspaceId": "workspaceid"
},
"tags": null,
"type": "Microsoft.Compute/virtualMachines/extensions",
"typeHandlerVersion": "1.0",
"virtualMachineExtensionType": "OmsAgentForLinux"
}
]
Azure CLI 語法問題
Azure CLI 可以在數個殼層環境中執行,但格式稍有不同。 如果使用 Azure CLI 命令時出現非預期的結果,請參閱如何順利使用 Azure CLI。
後續步驟
若要查看程式碼、目前問題和版本,請參閱 custom-script-extension-linux。