![](/img/trans.png)
[英]How to configure the endpoints for the “new” windows azure virtual machine?
[英]Configure an Azure windows virtual machine using Ansible
我正在尝试将基础架构作为代码学习,为此我使用 Terraform。 我还试图了解如何使用 Ansible 管理 VM 配置。 With Terraform, I'm able to create an Azure Windows virtual machine without problems, but I'm trying to understand why Ansible is not able to connect via SSH to the virtual machine. 不幸的是,我发现的所有示例都在谈论 Linux 虚拟机,但我需要创建一个 Windows 虚拟机。
这是用于创建 VM 的 Terraform 代码
resource "azurerm_network_security_group" "nsg" {
name = "SSH"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
security_rule {
name = "SSH"
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
tags = {
environment = "Test"
}
}
resource "azurerm_subnet_network_security_group_association" "secgroup-assoc" {
subnet_id = azurerm_subnet.subnet.id
network_security_group_id = azurerm_network_security_group.nsg.id
}
resource "azurerm_windows_virtual_machine" "runner" {
name = "runner"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
size = "Standard_B2s"
admin_username = "runner_admin"
admin_password = "*****"
network_interface_ids = [azurerm_network_interface.network_interface.id]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
disk_size_gb = 64
}
source_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2022-datacenter-azure-edition-smalldisk"
version = "latest"
}
connection {
host = self.public_ip_address
user = "runner_admin"
type = "ssh"
private_key = file("~/.ssh/id_rsa")
timeout = "4m"
agent = false
}
}
这是 Ansible 的库存文件
[runners]
<VM public IP> ansible_connection=ssh ansible_user=runner_admin
这是 Ansible 剧本
- name: Install Dependencies
hosts: runners
tasks:
- name: Install git
win_chocolatey:
name: git
state: present
先感谢您
要通过 SSH 连接到 Windows 虚拟机,您需要在 ZAEA23489CE3AA9B6406EBB283 中安装 SSH 服务器。
由于 Windows VM 没有任何默认 SSH 不像 Linux VM
您可以在 Windows VM 上安装 OpenSSH 服务器。
然后您将能够使用 Ansible 通过 SSH 连接到您的 Windows VM
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.