答案 0 :(得分:1)
您可以在GitHub上查看link。
公开配置
{
"fileUris": ["http://MyAccount.blob.core.windows.net/vhds/MyShellScript.sh"],
"commandToExecute": " sh MyShellScript.sh"
}
受保护的配置
{
"storageAccountName": "MyAccount",
"storageAccountKey": "Mykey"
}
使用模板,以下示例适用于Linux VM:
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "<extension-deployment-name>",
"apiVersion": "<api-version>",
"location": "<location>",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', <vm-name>)]"
],
"properties": {
"publisher": "Microsoft.OSTCExtensions",
"type": "CustomScriptForLinux",
"typeHandlerVersion": "1.5",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"<url>"
],
"commandToExecute": "<command>"
},
"protectedSettings": {
"storageAccountName": "<storage-account-name>",
"storageAccountKey": "<storage-account-key>"
}
}
}
更新
如果您想使用Python SDK执行此操作,请参阅以下示例。
##Using Azure Custom Script to execute script inside VM
GROUP_NAME = 'shuicli'
vmname = 'shui'
ext_type_name = 'CustomScriptForLinux'
ext_name = 'shuitest'
params_create = {
'location': 'eastus',
'publisher': 'Microsoft.OSTCExtensions',
'virtual_machine_extension_type': ext_type_name,
'type_handler_version': '1.0',
'auto_upgrade_minor_version': True,
'settings': {
'fileUris': ["https://shuilinuxdiag336.blob.core.windows.net/customscriptfiles/test.sh"],
'commandToExecute': 'sh test.sh'
},
'protected_settings' : {
'storageAccountName': 'shuilinuxdiag336',
'storageAccountKey': '<your storage account key>'
},
}
ext_poller = compute_client.virtual_machine_extensions.create_or_update(
GROUP_NAME,
vmname,
ext_name,
params_create,
)
ext = ext_poller.result()