无法在使用打包器创建的Azure VM中进行SSH

无法在使用打包器创建的Azure VM中进行SSH,azure,ssh,terraform,packer,Azure,Ssh,Terraform,Packer,因此,我正在使用Packer创建一个Azure映像 { "builders": [{ "type": "azure-arm", "client_id" : "{{user `client_id`}}", "client_secret" : "{{user `client_secret`}}", "subscription_id": "{{user `subscription_id`}}", "tenant_id" : "{{us

因此,我正在使用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...

}
当我启动虚拟机时,权限被拒绝(publickey、gssapi keyex、gssapi with mic)。当我尝试在虚拟机中使用SSH时

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

另外,让我恼火的是,当我通过Packer创建Centos映像时,没有使用Ansible(实际上只是一个Centos映像)对其进行配置,并将其与缩放集一起使用。。。我也不能在它的SSH


感觉像是Packer制造了一些令人讨厌的东西。

看起来您正在跳过取消提供步骤,这是清空网络和本地帐户配置以及重新使用映像后必须执行的步骤

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

/usr/sbin/waagent-force-deprovision+user&&export-HISTSIZE=0&&sync
请看下面的示例:


Azure文档:

ohh,我应该在ansible资源调配之前还是之后添加它?@KostasDemiris这必须是最后一步,因为在取消资源调配之后,它会关闭虚拟机并捕获映像。因此,我添加了您链接到的代码段,并且我能够通过SSH连接到虚拟机。但是,我注意到我想要在启动时运行的cloudinit文件(来自Terraform)没有被应用。它试图在root创建和拥有的/etc/gitlab/gitlab.rb文件中进行更改。@KostasDemiris Azure中支持cloud init的图像和操作系统列表在这里,在您的打包文件中,我看到了CentOS 7.3,而目前仅支持7.7