2016-04-25 84 views
0

两者完美的下载,解压缩并执行我的所有蝙蝠和的.msi我Azure的RM虚拟机文件本地代码工作的这些线,我在注入PowerShell命令Azure的RM虚拟机我已经通过一个ARM模板进行了部署,我疯狂地修改了它,因为我对这一切都很陌生,所以它可能已经充满了漏洞。试图通过JSON模板自定义扩展

我一直在试图通过Azure的文件共享来拍摄他们,通过JSON自定义脚本扩展到没有availe,也一直试图让他们向上穿过的blob容器具有相同的结果。我一直收到详细错误消息“网络路径找不到”。我一直在扫描日志,并找不到有关如何解决此问题的任何信息。我是否正在尝试以正确的方式实现?有没有更好的方式让我的部署动态参数自动安装?

cmdkey /add:$ArtifactsStorageAccountName.file.core.windows.net /u:$ArtifactsStorageAccountName /pass:$StorageAccountKey 
Copy-Item -Path $InstallCustomScriptExtensionScriptFilePath -Destination C:\ 
Copy-Item -Path $InstallCustomScriptExtensionZIPFilePath -Destination C:\ 
Unblock-File -Path C:\UnzipMetaforceInstall.ps1 
powershell -ExecutionPolicy Unrestricted -File C:\UnzipMetaforceInstall.ps1 
PowerShell net use Z: \\$ArtifactsStorageAccountName.file.core.windows.net\$FileShareName\InstallMetaforce /u:artifactsstoaccastst $StorageAccountKey 
PowerShell Copy-Item -Path Z:\UnzipMetaforceInstall.ps1 -Destination C:\ 
PowerShell Copy-Item -Path Z:\InstallMetaforce.zip -Destination C:\ 
PowerShell Unblock-File -Path C:\UnzipMetaforceInstall.ps1 
PowerShell -ExecutionPolicy Unrestricted -File C:\UnzipMetaforceInstall.ps1 

    { 
     "name": "InstallCustomScriptExtension", 
     "type": "extensions", 
     "location": "[variables('location')]", 
     "apiVersion": "2015-06-15", 
     "dependsOn": [ 
     "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmNamePrefix'), copyindex(1)))]", 
     "DSCConfig" 
     ], 
     "tags": { 
     "displayName": "InstallCustomScriptExtension" 
     }, 
     "properties": { 
     "publisher": "Microsoft.Compute", 
     "type": "CustomScriptExtension", 
     "typeHandlerVersion": "1.4", 
     "autoUpgradeMinorVersion": true, 
     "settings": { 
      "fileUris": [ 
      "[parameters('InstallCustomScriptExtensionScriptFilePath')]" 
      ], 
      "commandToExecute": "[parameters('CommandToExecuteCustomScript')]" 
     }, 
     "protectedSettings": { 
      "storageAccountName": "[parameters('ArtifactsStorageAccountName')]", 
      "storageAccountKey": "[parameters('StorageAccountKey')]" 
     } 
     } 
    } 

期待着我能得到的任何帮助,我一直坚持这一步大约两个星期了。如果您需要任何其他信息,或者如果我不清楚,请告诉我,我会看看我能做些什么。第一次发帖,长时间阅读。

回答

0

本周末我设法破解它。通过PowerShell/JSON参数使我的脚本动态变化,它的作用就像魅力一样。

 { 
     "name": "InstallCustomScriptExtension", 
     "type": "extensions", 
     "location": "[variables('location')]", 
     "apiVersion": "2015-06-15", 
     "dependsOn": [ 
     "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmNamePrefix'), copyindex(1)))]", 
     "DSCConfig" 
     ], 
     "tags": { 
     "displayName": "InstallCustomScriptExtension" 
     }, 
     "properties": { 
     "publisher": "Microsoft.Compute", 
     "type": "CustomScriptExtension", 
     "typeHandlerVersion": "1.4", 
     "autoUpgradeMinorVersion": true, 
     "settings": { 
      "fileUris": [ 
      "[concat(parameters('_artifactsLocation'), '/', parameters('InstallCustomScriptExtensionScriptFilePath'))]" 
      ], 
      "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', parameters('InstallCustomScriptExtensionScriptFilePath'), ' -ArtifactsStorageAccountName ', parameters('ArtifactsStorageAccountName'), ' -FileShareName ', parameters('FileShareName'), ' -StorageAccountKey ', parameters('StorageAccountKey'))]" 
     }, 
     "protectedSettings": { 
      "storageAccountName": "[parameters('ArtifactsStorageAccountName')]", 
      "storageAccountKey": "[parameters('StorageAccountKey')]" 
     } 
     } 
    } 

我解压脚本的内部现在看起来是这样的:

param(
[string]$ArtifactsStorageAccountName, 
[string]$FileShareName, 
[string]$StorageAccountKey 
) 

PowerShell net use Z: \\$ArtifactsStorageAccountName.file.core.windows.net\$FileShareName\Install /u:$ArtifactsStorageAccountName $StorageAccountKey; PowerShell Copy-Item -Path Z:\Install.zip -Destination C:\; 
$shell = New-Object -ComObject shell.application 
$zip = $shell.NameSpace("C:\Install.zip") 
MkDir("C:\Install") 
foreach ($item in $zip.items()) { 
$shell.Namespace("C:\Install").CopyHere($item) 
} 

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force 

cd "C:\Install" 
Unblock-File -Path "C:\Install\Install.ps1" 
"C:\Install\Install.ps1" | Invoke-Expression 

它可能需要一些更多的工作,在我的JSON模板中的受保护的设置可能是不必要的,但目前它的工作我现在有一个可以继续构建的单击部署。

0

“网络路径无法找到。”导致我相信这是一种在similar situation here,我认为重视蔚蓝的文件与脚本一个网络驱动器并不总是可靠的。我已经给出了解决方案,直接从链接主题中的Azure文件下载,我认为这也可以帮助你。让我知道如果它不适合你。

+0

非常感谢凯赵,请尽快看一看! :) – Stefan

0

您还可以看看样品在这里:

https://github.com/bmoore-msft/AzureRM-Samples

再看看文件夹:

https://github.com/bmoore-msft/AzureRM-Samples/tree/master/VMCSEInstallFilePS

该文件夹中的示例模板使用自定义脚本扩展来从Azure blob存储(或其他网址)安装文件。

回购的根目录包含一个PowerShell脚本,做两件事情:

  1. 副本从本地机器(如建机)安装到Azure存储的文件,并用sasToken和
  2. 将其固定
  3. 部署AzureRM模板和通过URI和sasToken为团块到部署。

另请注意样本中的“forceUpdateTag”(请参阅​​:Issues deploying dscExtension to Azure VMSS)。如果您需要反复部署json模板,则需要在虚拟机已存在时运行扩展(您也可以通过PowerShell删除AzureRMVMExtension,标记可能更快)。

0

如果你的脚本不包括任何秘密或知识产权,你可以把它上传到Blob存储容器和访问策略设置为“BLOB”(而不是“私人‘),然后你不’不必担心SAS令牌。

此模板与Blob存储和PowerShell工作对我来说(今天2016年4月28日)。

{ 
    "type": "Microsoft.Compute/virtualMachines/extensions", 
    "name": "[concat(variables('vmName'),'/CustomScriptExtension')]", 
    "apiVersion": "2015-06-15", 
    "location": "[resourceGroup().location]", 
    "tags": { 
    "displayName": "CustomScriptExtension" 
    }, 
    "dependsOn": [ 
    "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]" 
    ], 
    "properties": { 
    "publisher": "Microsoft.Compute", 
    "type": "CustomScriptExtension", 
    "typeHandlerVersion": "1.8", 
    "settings": { 
     "fileUris": [ "[parameters('launchScriptBlobUri')]" ], 
     "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -file ',parameters('scriptFileName'))]" 
    } 
    } 
} 
+0

也许微软可以解释为什么我的其他扩展有类型='扩展',但这一个有type ='Microsoft.Compute/virtualMachines/extensions',但它今天起作用。 –

+0

我认为他们在几个月前改变了它,当你滚动浏览数十亿指南时,它确实看起来像它。 :) – Stefan