Search code examples
azure-resource-managerazure-rm-templateazure-linux

Domain Join Azure Linux VM with ARM template


Is there any way we can domain join Azure Linux VM with ARM template? Like we have domain join extension for Azure Windows VM?

Or any other way to achieve this in ARM template?

Thanks


Solution

  • I got the way to solve this using custom script extension:

    ARM will look like :

    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "apiVersion": "2019-07-01",
      "name": "[concat(parameters('virtualMachineName'),'/joindomain')]",
      "location": "[parameters('location')]",
      "comments": "CustomScript - JsonADDomainExtension",
      "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
      ],
      "properties": {
        "autoUpgradeMinorVersion": true,
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.0",
        "settings": {
          "fileUris": [
            "[concat(uri(deployment().properties.templateLink.uri, 'script.sh')
          ]
        },
        "protectedSettings": {
          "commandToExecute": "[concat('sh script.sh ',parameters('domainName'), ' ', parameters('domainJoinUserName'), ' ', parameters('domainJoinUserPassword'))]"
        }
      }
    }
    

    Script.sh will look like :

    echo $3 | sudo realm join $1 -U $2
    sudo authconfig --enablesssd --enablesssdauth --enablemkhomedir --update