繁体   English   中英

无法在使用 Packer 创建的 Azure VM 中使用 SSH

[英]Unable to SSH in Azure VM created with Packer

所以,我正在使用 Packer 创建一个 Azure 映像。

{
  "builders": [{
    "type": "azure-arm",

    "client_id"      : "{{user `client_id`}}",
    "client_secret"  : "{{user `client_secret`}}",
    "subscription_id": "{{user `subscription_id`}}",
    "tenant_id"      : "{{user `tenant_id`}}",

    "managed_image_resource_group_name": "{{user `resource_group`}}",
    "managed_image_name": "CentOS7_w_GitlabCE_{{timestamp}}",

    "os_type"        : "Linux",
    "image_publisher": "OpenLogic",
    "image_offer"    : "CentOS",
    "image_sku"      : "7.3",
    "image_version"  : "latest",

    "location": "{{user `location`}}",
    "vm_size" : "Standard_DS2_v2"
  }],
  "provisioners": [
    {
      "type": "ansible",
      "playbook_file": "./gitlab/ansible/install-gitlab.yml",
      "extra_arguments": [
        "-vvvv"
      ]
    }
  ]
}

该图像创建得很好,并且位于 Azure 中我的资源组中。

然后,我在 Terraform 中输入它的详细信息以创建一个比例集。

data "azurerm_image" "image" {
  count = "${var.create_gitlab ? 1 : 0}"

  //notice: the image must have been created beforehand by Packer (inside the specific resource group)
  name                = "${var.vm_img_built_via_packer}"
  resource_group_name = "${var.resource_group}"
}

resource "azurerm_virtual_machine_scale_set" "vmss" {

...other stuff....

  storage_profile_image_reference {
    // reference the id of the custom image created with Packer
    id = "${data.azurerm_image.image.id}"
  }

  os_profile {
    computer_name_prefix = "${var.prefix}-vm"
    admin_username       = "someuser"
  }

  os_profile_linux_config {
    disable_password_authentication = true

    ssh_keys {
      path     = "/home/someuser/.ssh/authorized_keys"
      key_data = "${file(var.someuser_ssh_pubkey)}"
    }
  }

...other stuff...

}

当我启动 VMSS 时,我得到Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 当我尝试在 VM 中使用 SSH 时。

但是,如果我使用相同的 Centos 映像但直接来自 Azure,则可以在 VM 中使用 SSH。

另外,让我生气的是,当我通过 Packer 创建 Centos 映像时,没有使用 Ansible(实际上只是一个 Centos 映像)配置它,并将其与规模集一起使用......我也无法在其中使用 SSH。

感觉像 Packer 做了一些令人讨厌的事情。

看起来您正在跳过取消配置步骤https://packer.io/docs/builders/azure-arm.html#deprovision ,这是清空网络和本地帐户配置以及之后重用图像所必需的。

对于 Linux,您需要执行以下命令:

/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync

看看这里的例子: https : //github.com/hashicorp/packer/blob/master/examples/azure/linux_custom_image.json

Azure 文档: https : //docs.microsoft.com/en-us/azure/virtual-machines/linux/capture-image#step-1-deprovision-the-vm

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM