这可能很长,所以请忍受我。
目标:使用terraform创建azure-vm,azure-devops发布管道可以使用“目标计算机上的远程PowerShell”步骤来部署和启动Windows服务。
问题:使用Terraform,RDP到VM创建VM并配置wsman和powershell以允许VM上具有远程PowerShell之后,我尝试将新的vm添加到本地计算机上的Trustedhosts。失败并显示以下消息:
WSManFault 消息=客户端无法连接到请求中指定的目标。验证目标上的服务正在运行 并正在接受请求。请查阅日志和文档以了解 在目标(最常见的是IIS或 WinRM。如果目标是WinRM服务,请运行以下命令 目标上的命令以分析和配置WinRM服务: “ winrm quickconfig”。
错误号:-2144108526 0x80338012客户端无法连接到 请求中指定的目的地。验证服务是否在 目标正在运行并且正在接受请求。查阅日志并 在以下站点上运行的WS-Management服务的文档 目标,最常见的是IIS或WinRM。如果目的地是 WinRM服务,在目标上运行以下命令进行分析 并配置WinRM服务:“ winrm quickconfig”。
以下是我创建和设置VM的步骤:
在Powershell中,我执行以下操作:
Connect-AzAccount -Tenant [TenantName]
选择AzSubscription -Subscription [SubscriptionId]
$ cert = Get_AzKeyVaultCertificate -VaultName [vaultName] -Name [certificateName]
启用PSRemoting -SkipNetworkProfileCheck -Force
Get-ChildItem WSMan:\ Localhost \ Listener |在何处-属性键-EQ“ Transport = HTTP” | Remove-Item -Recurse
新项-路径WSMan:\ LocalHost \ Listener-传输HTTPS-地址* -CertificateThumbPrint $ cert.Thumbprint -Force
New-NetFirewallRule -DisplayName'Windows远程管理(HTTPS-In)'-名称'Windows远程管理(HTTPS-In)'-配置文件任意-LocalPort 5986-协议TCP
Disable-NetFirewallRule -DisplayName“ Windows远程管理(HTTP-In)”
在我的本地主机上,在az命令行中,执行: az登录 winrm设置winrm / config / client @ {TrustedHosts =“ [服务器DNS名称]”}
这是失败的地方。
为什么我希望它能起作用?我以前使用Azure门户创建了一个VM,并使用这些步骤来启用HTTPS PSRemoting。 Azure Devops能够通过HTTPS使用“在目标计算机上运行PowerShell”步骤成功部署到VM并启动服务。我还能够将门户创建的VM添加到本地计算机上的受信任主机列表中。
为了使发布管道正常工作,我必须添加一个命令行脚本步骤,将DNS名称添加到TrustedHosts。
我缺少什么使我无法将terraform创建的VM添加到受信任的主机?在这一点上,我还没有建立发布管道,因为我认为在成功将terraform创建的VM添加到受信任的主机之前,没有必要尝试建立发布管道。比较两个VM时,我在门户中看到的一个区别是,terraform创建的VM没有计算机名,而Portal创建的VM具有计算机名。我一直无法弄清楚为什么。
虽然我无法将DNS名称添加到我的TrustedHosts中,但是我能够建立安全的PSSession。
这是Terraform脚本:
provider "azurerm" {
version = "1.27.0"
subscription_id = "${var.subscription-id}"
tenant_id = "${var.ad-tenant-id}"
}
resource "azurerm_virtual_network" "vnet" {
name = "${var.vnet-name}"
address_space = ["10.0.0.0/16"]
location = "${var.location}"
resource_group_name = "${var.vm-resource-group-name}"
}
resource "azurerm_subnet" "subnet" {
name = "${var.subnet-name}"
resource_group_name = "${var.vm-resource-group-name}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
address_prefix = "10.0.1.0/24"
}
resource "azurerm_public_ip" "publicip" {
name = "${var.public-ip-name}"
location = "${var.location}"
resource_group_name = "${var.vm-resource-group-name}"
allocation_method = "Static"
domain_name_label = "${var.domain-name-label}"
}
resource "azurerm_network_security_group" "nsg" {
name = "${var.security-group-name}"
location = "${var.location}"
resource_group_name = "${var.vm-resource-group-name}"
security_rule {
name = "RDP"
priority = 300
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "WinRM"
priority = 310
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "5985-5986"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
resource "azurerm_network_interface" "nic" {
name = "${var.nic-name}"
location = "${var.location}"
resource_group_name = "${var.vm-resource-group-name}"
network_security_group_id = "${azurerm_network_security_group.nsg.id}"
enable_accelerated_networking = true
ip_configuration {
name = "${var.ip-config-name}"
subnet_id = "${azurerm_subnet.subnet.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${azurerm_public_ip.publicip.id}"
}
}
resource "azurerm_virtual_machine" "vm" {
name = "${var.vm-name}"
location = "${var.location}"
resource_group_name = "${var.vm-resource-group-name}"
network_interface_ids = ["${azurerm_network_interface.nic.id}"]
vm_size = "${var.vm-size}"
storage_os_disk {
name = "${var.disk-name}"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Premium_LRS"
}
delete_os_disk_on_termination = true
storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "${var.sku}"
version = "latest"
}
os_profile {
computer_name = "${var.vm-name}"
admin_username = "${var.vm-admin-id}"
admin_password = "${var.vm-admin-password}"
}
os_profile_secrets {
source_vault_id = "${var.keyvault-id}"
vault_certificates {
certificate_url = "${var.cert-secret-id}"
certificate_store = "My"
}
}
os_profile_windows_config {
}
tags = {
applicationidentifier = "casa"
applicationrole = "VM"
companycode = "C4"
CostCenterCode = "04-ENG"
Environment = "Dev/Test"
name = "casa-win-services"
owner = "captioncall_eng"
version = "1.0"
}
}
TIA, 达尔文
答案 0 :(得分:0)
我辩论删除此问题,但可能会对某人有所帮助。
事实证明,没有必要将DNS名称添加到受信任的主机。无需执行该步骤即可发布管道。