通过powershell部署Azure模板:“0”;模板参数JToken类型无效";
我正在尝试使用ARM模板通过Powershell部署虚拟机 我想使用模板参数将SSH公钥传递到模板中 这些参数在模板文件中定义如下:通过powershell部署Azure模板:“0”;模板参数JToken类型无效";,azure,azure-powershell,azure-deployment,azure-template,Azure,Azure Powershell,Azure Deployment,Azure Template,我正在尝试使用ARM模板通过Powershell部署虚拟机 我想使用模板参数将SSH公钥传递到模板中 这些参数在模板文件中定义如下: "parameters": { "sshPublicKey": { "type": "string" } }, 下面是powershell脚本,我从文件中加载公钥并将其添加为模板参数 $publicKey = (Get-Content .\keys\id_rsa.pub) "Public
"parameters": {
"sshPublicKey": {
"type": "string"
}
},
下面是powershell脚本,我从文件中加载公钥并将其添加为模板参数
$publicKey = (Get-Content .\keys\id_rsa.pub)
"Public Key is string of length {0}" -f $publicKey.Length
$parametersObject = @{"sshPublicKey" = $publicKey }
"Running the Deployment now"
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile .\template.json -TemplateParameterObject $parametersObject
我遇到了以下令人沮丧的错误:
新AzResourceGroupDeployment:9:02:09 AM-错误:
代码=无效模板;消息=部署模板验证失败:
'模板参数JToken类型无效。应为“字符串,Uri”。
实际“对象”。请看
有关用法的详细信息。
在
C:\users\sheph\Documents\GitHub\aspnet核心linux练习\setup ubuntu nginx\deploy.ps1:20
字符:1
+新AzResourceGroupDeployment-ResourceGroupName$ResourceGroupName-。。。
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+CategoryInfo:NotSpecified:(:)[New AzResourceGroupDeployment],异常
+FullyQualifiedErrorId:Microsoft.Azure.Commands.ResourceManager.cmdlet.Implementation.NewAzureResourceGroupDeploymentCmdlet
起初我认为这是字符串长度的问题。(该键的长度为402个字符)。但是如果我用402个连续的“A”字符替换它,我就不会得到错误
我有另一个例子,它使用一个模板参数文件而不是一个模板参数对象,这也很有效
有什么方法可以让它工作吗?问题是我的$publicKey值包含一个换行符 我通过调用
Trim
方法修复了它
$publicKey = (Get-Content .\keys\id_rsa.pub);
$publicKey = $publicKey.Trim();
$parametersObject = @{"sshPublicKey" = $publicKey }
当输入无法转换为arm模板引擎所期望的内容时,这是一个一般性错误,因此,在出现此错误时,仅对所有内容进行修剪并没有真正的帮助(通常)