我正在使用terraform创建我的Ubuntu VM,随后将使用ansible配置它们。
但是,ansible 需要设置用户和 ssh 密钥才能连接,因此用于 ansible 的公钥需要位于服务器上的authorized_keys
文件中。
如果我使用我的 ssh 公钥,它将在我的机器上工作,但它不适用于其他机器或构建服务器,因为它们没有私钥。
创建新密钥而不覆盖当前密钥的命令是什么?
我应该将此密钥签入 git 以便将相同的密钥传递给 terraform 吗?
如何将我的地形任务更改为使用版本控制中的密钥?
当前地形任务:
resource "azurerm_virtual_machine" "client-vm" {
name = "${var.prefix}-${var.client_name}-vm"
resource_group_name = var.resource_group_name
location = var.resource_group_location
network_interface_ids = [azurerm_network_interface.network-interface.id]
vm_size = "Standard_D2s_v3"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
#TODO: Switch to SSH Keys
os_profile {
computer_name = "${var.client_name}"
admin_username = var.username
admin_password = var.password
}
os_profile_linux_config {
disable_password_authentication = false
}
}
是的,至少如果这是您的云提供商处理SSH密钥的方式。(例如,AWS 确实如此(:
resource "aws_instance" "web" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
key_name = "name_of_the_aws_keypair"
}