Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builder googlecompute preserves intermediate machine's hostname instead of set hostname to instance name for newly created machines #103

Open
EmilMaksimov opened this issue Jul 7, 2022 · 3 comments

Comments

@EmilMaksimov
Copy link

  • Packer version 1.8.2
  • Host Windows Server 2019

This issue applies to the googlecompute builder.

Newly created VM based on a Packer created Windows Image in Google Compute gets hostname set to Packer intermediate machine's hostname (packer-62bd6611-ac4b-9422-203a-ed4b75e1ac50). Every next VM gets hostname set to the same value.

Expected behaviour - Newly create VM get hostname set to instance name

@nywilken nywilken self-assigned this Jul 29, 2022
@nywilken
Copy link
Member

Hi @EmilMaksimov apologies for the delay here. Is this still an issue for you?

To confirm you are seeing that creating a new image from a Packer built image is reusing the name of the intermediate instance (used to create the image) as the hostname for all newly created images. Is my understanding correct?

If so, are the new instances being created manually or via some automated process like Packer or Terraform?

If you could provide the template used for creating the initial image that would be helpful. From my understanding hostnames are generated by GCP unless a specific hostname is set at creation time.

@nywilken nywilken removed their assignment Aug 31, 2022
@EmilMaksimov
Copy link
Author

EmilMaksimov commented Sep 1, 2022

Hi @nywilken ,

Your understanding is correct.

New instances based on newly created packer image are created manually.

Template is very simple. Only install SSH and setup user account. Base image is Google'stock image - windows-server-2019-dc-v20220812.

Let me know if any other troubleshooting needs to be done.

packer {
  required_version = ">= 1.1.0"
}


variables {
  gcp_account_file            = ""
  gcp_disk_size               = ""
  gcp_image_family            = ""
  gcp_image_description       = ""
  gcp_machine_type            = ""
  gcp_project_id              = ""
  gcp_source_image            = ""
  gcp_ssh_username            = ""
  gcp_ssh_password            = ""
  gcp_zone                    = ""
  gcp_network_project_id      = ""
  gcp_subnetwork              = ""
  gcp_coverity_user           = ""
  gcp_coverity_pass           = ""
  gcp_artifactory_user        = ""
  gcp_artifactory_api_key     = ""
  gcp_artifactory_url         = ""
  gcp_user                    = ""
  gcp_pass                    = ""
  gcp_jenkins_remote_location = ""
  gcp_image_template_name     = ""
  dry_run                     = null
  time_stamp                  = ""
  job_info                    = ""
  git_commit                  = ""
  release_notes               = ""
}

source "googlecompute" "gcp_agent" {
  account_file       = "${var.gcp_account_file}"
  disk_size          = "${var.gcp_disk_size}"
  image_family       = "${var.gcp_image_family}"
  image_name         = "${var.gcp_image_template_name}-${var.time_stamp}"
  machine_type       = "${var.gcp_machine_type}"
  project_id         = "${var.gcp_project_id}"
  source_image       = "${var.gcp_source_image}"
  ssh_username       = "${var.gcp_ssh_username}"
  ssh_password       = "${var.gcp_ssh_password}"
  zone               = "${var.gcp_zone}"
  network_project_id = "${var.gcp_network_project_id}"
  subnetwork         = "${var.gcp_subnetwork}"
  use_internal_ip    = true
  omit_external_ip   = true
  skip_create_image  = "${var.dry_run}"
  image_labels = {
  jenkins-info = "${var.job_info}",
  git-commit = "${var.git_commit}",
  release-notes = "${var.release_notes}"
  }
  metadata = {
    windows-startup-script-cmd = "powershell Start-Sleep -s 45 & net user ${var.gcp_ssh_username} \"${var.gcp_ssh_password}\" /add /y & wmic UserAccount where Name=\"${var.gcp_ssh_username}\" set PasswordExpires=False & net localgroup administrators ${var.gcp_ssh_username} /add & powershell Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 & powershell Start-Service sshd & powershell Set-Service -Name sshd -StartupType 'Automatic' & powershell New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 & powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"Set-ExecutionPolicy -ExecutionPolicy bypass -Force\""
  }
  communicator = "ssh"
  ssh_timeout = "1h"
  state_timeout = "15m"
}

build {
  description = "Build windows base image"

  sources = ["source.googlecompute.gcp_agent"]
  
}

@skorobogatydmitry
Copy link

I have the same problem with AlmaLinux 9. In my case it's a configuraiton problem, as provisioning script the config has is very complex. Hostname gets updated to the right one after reboot.
Are there any known cases causing hostname to freeze till reboot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants