Azure 在创建时将自定义数据从容器传递到VM

Azure 在创建时将自定义数据从容器传递到VM,azure,azure-virtual-machine,Azure,Azure Virtual Machine,我想传递自定义数据,它是BLOB存储中的shell脚本。我是否可以指定脚本的URI,并让VM在启动时执行它 如何在模板中指定信息?您可以在GitHub上查看 公共配置 { "fileUris": ["http://MyAccount.blob.core.windows.net/vhds/MyShellScript.sh"], "commandToExecute": " sh MyShellScript.sh" } { "storageAccountName": "MyAccount

我想传递自定义数据,它是BLOB存储中的shell脚本。我是否可以指定脚本的URI,并让VM在启动时执行它

如何在模板中指定信息?

您可以在GitHub上查看

公共配置

{
  "fileUris": ["http://MyAccount.blob.core.windows.net/vhds/MyShellScript.sh"],
  "commandToExecute": " sh MyShellScript.sh"
}
{
  "storageAccountName": "MyAccount",
  "storageAccountKey": "Mykey"
}
保护配置

{
  "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>"
    }
  }
}
{
“类型”:“Microsoft.Compute/VirtualMachine/extensions”,
“名称”:“,
“版本”:“,
“地点”:“,
“dependsOn”:[
[concat('Microsoft.Compute/virtualMachines/',)]
],
“财产”:{
“发布者”:“Microsoft.OSTCExtensions”,
“类型”:“CustomScriptForLinux”,
“typeHandlerVersion”:“1.5”,
“autoUpgradeMinorVersion”:正确,
“设置”:{
“文件URI”:[
""
],
“commandToExecute”:”
},
“protectedSettings”:{
“storageAccountName”:“”,
“storageAccountKey”:”
}
}
}
更新:

如果您想使用PythonSDK来实现这一点,请参见下面的示例

##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()
###使用Azure自定义脚本在VM内执行脚本
组名称='shuicli'
vmname=‘水’
ext_type_name='CustomScriptForLinux'
ext_name='shuitest'
参数创建={
‘地点’:‘伊斯图’,
'publisher':'Microsoft.OSTCExtensions',
“虚拟机扩展类型”:扩展类型名称,
'type_handler_version':'1.0',
“自动升级次要版本”:True,
“设置”:{
'文件URI':[“https://shuilinuxdiag336.blob.core.windows.net/customscriptfiles/test.sh"],
“commandToExecute”:“sh test.sh”
}, 
“受保护的_设置”:{
'storageAccountName':'shuilinuxdiag336',
“storageAccountKey”:”
},
}
ext\u poller=compute\u client.virtual\u machine\u extensions.create\u或\u update(
组名称,
vmname,
分机名,
params_create,
)
ext=ext_poller.result()

是否存在实际使用fileURI和commandToExecute的示例?我不确定提供的密钥应该放在()上的模板中的何处。@varunvenbar看到了这一点。如果您使用Visual Studio,您可以轻松地添加新资源。我无法将两者合并在一起。我不确定JSON的“properties”键如何适合VMtemplate@VarunVembar你能分享你当前的模板吗?您只需将其部署到Azure即可。