jetbrains-infra / packer-builder-vsphere

Packer plugin for remote builds on VMware vSphere
Mozilla Public License 2.0
542 stars 175 forks source link

Unexpected connetion loss with VSphere (UbuntuServer 18.04) #254

Open joudaon opened 5 years ago

joudaon commented 5 years ago

I have the following template for making UbuntuServer 18.04.1 image template:

{
  "variables": {
    "USERNAME": "administrator",
    "PASSWORD": "password",
    "SERVER": "192.168.103.44",
    "DATASTORE": "datastore 192.168.103.13",
    "NETWORK": "VM Network",
    "HOST": "192.168.103.13",
    "CLUSTER": "",
    "VMNAME": "ubuntuserver1804",
    "ISO": "[datastore] ISOS/ubuntu-18.04.1-server-amd64.iso",
    "SSH_USERNAME": "administrator",
    "SSH_PASSWORD": "password",
    "CPUS":         "2",
    "MEMORY_SIZE":  "2048",
    "DISK_SIZE":    "10240"
  },
  "builders": [
    {
      "type": "vsphere-iso",
      "vcenter_server":      "{{user `SERVER`}}",
      "username":            "{{user `USERNAME`}}",
      "password":            "{{user `PASSWORD`}}",
      "insecure_connection": "true",
      "datastore": "{{user `DATASTORE`}}",
      "network":   "{{user `NETWORK`}}",
      "vm_name":   "{{user `VMNAME`}}",
      "host":      "{{user `HOST`}}",
      "resource_pool":         "packer",

      "guest_os_type": "ubuntu64Guest",

      "ssh_username": "{{user `SSH_USERNAME`}}",
      "ssh_password": "{{user `SSH_PASSWORD`}}",
      "ssh_timeout":           "24h",
      "ssh_keep_alive_interval":  "5s",
      "CPUs":                     "{{user `CPUS`}}",
      "RAM":                      "{{user `MEMORY_SIZE`}}",

      "disk_controller_type":  "pvscsi",
      "disk_size":        "{{user `DISK_SIZE`}}",
      "disk_thin_provisioned": true,

      "network_card": "vmxnet3",
      "shutdown_command": "echo '{{ user `SSH_PASSWORD` }}'|sudo -S shutdown -P now",
      "iso_paths": [
        "{{user `ISO`}}"
      ],
      "floppy_files": [
        "{{template_dir}}/http/preseed_vsphere_1804.cfg"
      ],
      "boot_command": [
        "<enter><wait><f6><wait><esc><wait>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
        "<bs><bs><bs>",
        "/install/vmlinuz ",
        "initrd=/install/initrd.gz ",
        "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
        "hostname={{ user `VMNAME` }} ",
        "grub-installer/bootdev=/dev/sda<wait> ",
        "fb=false debconf/frontend=noninteractive ",
        "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
        "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
        "file=/media/preseed_vsphere_1804.cfg",
        "<enter>"
      ],
      "boot_order": "disk,cdrom"
    }
  ],
  "provisioners": [
    {
      "environment_vars": [
        "DEBIAN_FRONTEND=noninteractive",
        "UPDATE=true",
        "DISABLE_IPV6=yes",
        "SSH_USERNAME={{user `SSH_USERNAME`}}",
        "SSH_PASSWORD={{user `SSH_PASSWORD`}}"
      ],
      "type": "shell",
      "execute_command": "echo '{{ user `SSH_PASSWORD` }}' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
      "expect_disconnect": true,
      "scripts": [
        "{{template_dir}}/../scripts/ubuntu/change_keyboard_layout.sh",
        "{{template_dir}}/../scripts/ubuntu/update.sh",
        "{{template_dir}}/../scripts/ubuntu/enable_ssh_login.sh",
        "{{template_dir}}/../scripts/ubuntu/install_basic_packages.sh",
        "{{template_dir}}/../scripts/ubuntu/minimize.sh",
        "{{template_dir}}/../scripts/ubuntu/cleanup.sh"
      ]
    }
  ]
}

When I execute "packer build vpshere_ubuntu18.04.1.json" the terminal output goes well, the OS is installed but in the shell provider, randomly the connection is lost with the following output:

    vsphere-iso: Installing new version of config file /etc/lsb-release ...
    vsphere-iso: Installing new version of config file /etc/update-motd.d/50-motd-news ...
    vsphere-iso: motd-news.service is a disabled or a static unit, not starting it.
    vsphere-iso: (Reading database ... 55%
==> vsphere-iso: Power off VM...
==> vsphere-iso: Deleting Floppy image ...
==> vsphere-iso: Destroying VM...
.96:22: i/o timeout

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: Error removing temporary script at /tmp/script_132.sh: dial tcp 192.168.102.96:22: i/o timeout
==> Builds finished but no artifacts were created.

When this happends, before timeout rises, I go to VShpere client, and I open the machine and I can´t interact with it. That´s quite weird because direct interaction doesn´t work neither...

Has someone had this behaviour? How can I fix that?

Thank you.

VladRassokhin commented 5 years ago

I've seen similar behaviour when run apt-get dist-upgrade on fresh Ubuntu 18.04.2 and VM is stuck on Setting up systemd (237-3ubuntu10.24) ..., that's bug in systemd upgrade script (still have no idea how to workaround). Probably you're experience similar problem.

Try out removing script which updates packages.