【问题标题】:How to create two admin users using azure templates?如何使用 azure 模板创建两个管理员用户?
【发布时间】:2019-04-12 06:34:27
【问题描述】:

我正在准备一个新的 azure 模板来创建几个应该有两个管理员帐户的 CentOs 虚拟机。我可以毫无问题地创建一个管理员用户,但问题在于创建额外的用户。

我尝试创建两个 OSProfile:

 "osProfile": {
     "computerName": "[concat(parameters('vmName'), copyIndex(1))]",
     "adminUsername": "[parameters('adminUsername')]",
     "adminPassword": "[parameters('adminPassword')]"
  },
 "osProfile": {
     "adminUsername": "[parameters('secondUsername')]",
     "adminPassword": "[parameters('secondAdminPassword')]"
 },

我希望在模板部署期间创建两个用户。但无法在 azure 文档中找到任何信息。

【问题讨论】:

  • 我忘了说我正在创建的虚拟机是Linux机器CentOs
  • 可能你可以使用模板中的cloud-init创建多个用户,你可以看看我的另一个case

标签: azure templates authentication


【解决方案1】:

您需要使用 vm 脚本扩展来创建其他用户。 vm creation api 只允许定义一个用户。在template examples repo 中可以找到使用脚本扩展的示例。

{
    "type": "extensions",
    "name": "CustomScriptExtension",
    "apiVersion": "2017-03-30",
    "location": "[parameters('location')]",
    "dependsOn": [
        "[variables('vmName')]"
    ],
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.8",
        "autoUpgradeMinorVersion": true,
        "settings": {
            "fileUris": [
                "[concat(parameters('_artifactsLocation'), '/', variables('ScriptFolder'), '/', variables('ScriptFileName'), parameters('_artifactsLocationSasToken'))]"
            ],
            "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('scriptFolder'), '/', variables('scriptFileName'), ' ', variables('scriptParameters'))]"
        }
    }
}

或者您可以按原样提供脚本命令,例如:

New-LocalUser name -Password (ConvertTo-SecureString -AsPlainText -Force 'pwd_goes_here'); 
Add-LocalGroupMember -Group "Administrators" -Member name

你不能有换行符,所以改用;

【讨论】:

  • 我忘了提到我正在创建的虚拟机是 Linux 机器 CentOs。有没有办法在 Linux 机器上做到这一点?
  • 没关系,使用linux脚本扩展,可以在同一个repo中找到示例,可以运行自定义脚本,也可以使用cloud-init (blog post)
猜你喜欢
  • 2013-03-15
  • 1970-01-01
  • 1970-01-01
  • 2014-03-12
  • 2015-04-21
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
  • 1970-01-01
相关资源
最近更新 更多