通过 ARM 模板 DSC(或非 DSC)设置计算机描述
Set Computer Description via ARM template DSC (or not DSC)
我构建了一个嵌套的 ARM 模板,用于设置 VM 并将其添加到 Azure DSC 自动化服务器以进行最终配置。此设置利用以下 Git 资源来设置拉取服务器:
此源使用 ARM 模板中的 DSC 扩展来配置 VM,用于拉取服务器所在的位置、注册密钥、设置以及要应用的 DSC 节点配置,这是我配置机器的所有内容。
我的部分 DSC 配置需要更新机器描述:
Registry ChangeDescription
{
Ensure = "Present"
Key = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
ValueName = "srvcomment"
ValueData = "my-super-awesome-computer-description"
ValueType = "String"
}
我希望我的 ARM 模板能够将参数传递给最终用户在 ARM 部署时键入计算机描述的 DSC 配置(我将使用 Azure 模板部署作为 'stock' 图像供人们使用)。
ARM参数:
"computerDescription": {
"type": "string",
"metadata": {
"description": "The description name of the VM."
}
},
Microsoft.Compute/virtualMachines/extensions 属性:
{
"Name": "computerDescription",
"Value": "[parameters('computerDescription')]",
"TypeName": "System.String"
}
DSC:
Registry ChangeDescription
{
Ensure = "Present"
Key = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
ValueName = "srvcomment"
ValueData = $ComputerDescription
ValueType = "String"
}
根据 Git 上的源代码,我知道您可以将参数传递给 DSC 文件,因为这就是机器的设置方式,但我只能看到它被传递给 .ps1 实际为 DSC 设置机器的脚本。因此,我看不到如何将参数传递到我的节点配置完成设置的下一阶段。
我不一定需要在 DSC 点设置它,如果我知道如何,可以通过模板完成,或者也许有人可能知道的其他地方?本质上只需要设置一次。
有什么想法吗?
编辑 4c74356b41 问题。
我仍然不确定如何将参数 computerDescription
用作 commandToExecute
的字符串。这是我想出的 PS 脚本,但不知道如何将该字符串变成 PS.
的变量
Param ( [string] $psVariable )
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\" -Name "srvcomment" -Value $psVariable -PropertyType String
这是我的commandToExecute
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'))]"
我不确定将 computerDescription
参数放在哪里...?
如果您已经在使用 DSC 扩展加入 Azure Automation,则存在您可能不想更改的预定义配置。所以在你的情况下,我会说只使用脚本扩展和一个简单的 powershell 1 衬里来设置这个注册表值要容易得多,你可以使用 arm 模板
轻松地参数化它
我构建了一个嵌套的 ARM 模板,用于设置 VM 并将其添加到 Azure DSC 自动化服务器以进行最终配置。此设置利用以下 Git 资源来设置拉取服务器:
此源使用 ARM 模板中的 DSC 扩展来配置 VM,用于拉取服务器所在的位置、注册密钥、设置以及要应用的 DSC 节点配置,这是我配置机器的所有内容。
我的部分 DSC 配置需要更新机器描述:
Registry ChangeDescription
{
Ensure = "Present"
Key = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
ValueName = "srvcomment"
ValueData = "my-super-awesome-computer-description"
ValueType = "String"
}
我希望我的 ARM 模板能够将参数传递给最终用户在 ARM 部署时键入计算机描述的 DSC 配置(我将使用 Azure 模板部署作为 'stock' 图像供人们使用)。
ARM参数:
"computerDescription": {
"type": "string",
"metadata": {
"description": "The description name of the VM."
}
},
Microsoft.Compute/virtualMachines/extensions 属性:
{
"Name": "computerDescription",
"Value": "[parameters('computerDescription')]",
"TypeName": "System.String"
}
DSC:
Registry ChangeDescription
{
Ensure = "Present"
Key = "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
ValueName = "srvcomment"
ValueData = $ComputerDescription
ValueType = "String"
}
根据 Git 上的源代码,我知道您可以将参数传递给 DSC 文件,因为这就是机器的设置方式,但我只能看到它被传递给 .ps1 实际为 DSC 设置机器的脚本。因此,我看不到如何将参数传递到我的节点配置完成设置的下一阶段。
我不一定需要在 DSC 点设置它,如果我知道如何,可以通过模板完成,或者也许有人可能知道的其他地方?本质上只需要设置一次。
有什么想法吗?
编辑 4c74356b41 问题。
我仍然不确定如何将参数 computerDescription
用作 commandToExecute
的字符串。这是我想出的 PS 脚本,但不知道如何将该字符串变成 PS.
Param ( [string] $psVariable )
New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\" -Name "srvcomment" -Value $psVariable -PropertyType String
这是我的commandToExecute
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('asdfcseScriptFolder'), '/', variables('asdfcseScriptFileName'))]"
我不确定将 computerDescription
参数放在哪里...?
如果您已经在使用 DSC 扩展加入 Azure Automation,则存在您可能不想更改的预定义配置。所以在你的情况下,我会说只使用脚本扩展和一个简单的 powershell 1 衬里来设置这个注册表值要容易得多,你可以使用 arm 模板
轻松地参数化它