26

AzureRM テンプレートに次のリソースがある場合、そのcommandToExecute部分の一重引用符をどのようにエンコードしますか?

{
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "name": "[concat(variables('vmNameMaster'), copyIndex(), '/sethost')]",
  "apiVersion": "2015-06-15",
  "location": "[resourceGroup().location]",
  "copy": {
      "name": "extensionLoopNode",
      "count": "[variables('masterCount')]"
  },
  "dependsOn": [
      "[concat('Microsoft.Compute/virtualMachines/', variables('vmNameMaster'), copyIndex(),'/extensions/DockerExtension')]"
  ],
  "properties": {
    "publisher": "Microsoft.OSTCExtensions",
    "type": "CustomScriptForLinux",
    "typeHandlerVersion": "1.4",
    "settings": {
      "fileUris": [ ],
      "commandToExecute": "[concat('/bin/bash -c \'echo \"export DOCKER_HOST=:2375\" >> /home/', parameters('adminUsername') ,'/.profile\'')]",
      "timestamp": 123456789
    }
  }
},
4

4 に答える 4

18

私は変数でこれを回避しました:

"variables": {
    "singleQuote": "'",
},
...
"settings": {
    "fileUris": [],
    "commandToExecute": "[concat('/bin/bash -c ', variables('singleQuote'), 'echo \"export DOCKER_HOST=:2375\" >> /home/', parameters('adminUsername') ,'/.profile', variables('singleQuote'))]",
}

エレガントではありませんが、機能します。

于 2016-05-18T07:39:34.173 に答える
-5

commandToExecute 部分で一重引用符をエンコードする必要はありません。以下の json セグメントは、http://jsonlint.com/ で有効な json として検証されています

{
    "type": "Microsoft.Compute / virtualMachines / extensions ",
    "name": "[concat(variables('vmNameMaster'), copyIndex(), '/sethost')]",
    "apiVersion": "2015-06-15",
    "location": "[resourceGroup().location]",
    "copy": {
        "name": "extensionLoopNode",
        "count": "[variables('masterCount')]"
    },
    "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', variables('vmNameMaster'), copyIndex(),'/extensions/DockerExtension')]"
    ],
    "properties": {
        "publisher": "Microsoft.OSTCExtensions",
        "type": "CustomScriptForLinux",
        "typeHandlerVersion": "1.4",
        "settings": {
            "fileUris": [],
            "commandToExecute": "[concat('/bin/bash -c 'echo \"export DOCKER_HOST=:2375\" >> /home/', parameters('adminUsername') ,'/.profile'')]",
            "timestamp": 123456789
        }
    }
}
于 2015-11-30T07:03:35.850 に答える