mitchellh / vagrant-google

Vagrant provider for GCE.
Apache License 2.0
334 stars 100 forks source link

SSH never times out #233

Open Temikus opened 4 years ago

Temikus commented 4 years ago

Well this is embarassing, see run_instance.rb:

          unless env[:terminated]
            env[:metrics]["instance_ssh_time"] = Util::Timer.time do
              # Wait for SSH to be ready.
              env[:ui].info(I18n.t("vagrant_google.waiting_for_ssh"))
              while true
                # If we're interrupted just back out
                break if env[:interrupted]
                break if env[:machine].communicate.ready?
                sleep 2
              end
            end
            @logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
            env[:ui].info(I18n.t("vagrant_google.ready_ssh")) unless env[:interrupted]
          end

We need to add some communication and a timeout here.

gdubicki commented 2 years ago

I just tried to use this in a new GCP project where I forgot to add my public SSH key as project metadata and starting a new instance was hanging forever on:

==> default: Waiting for instance to become "ready"...
==> default: Machine is booted and ready for use!
==> default: Waiting for Communicator to become available...

...until I terminated it manually.

Is this the same problem or a similar one but in a different provisioning stage, @Temikus ?

I did https://github.com/mitchellh/vagrant-google/pull/258 as a weak workaround, to prevent other people from wasting time the same way (I think that the best solution would be to implement validation for this in the plugin code. But it looks like fog-google does not have "get_project_SSH_keys" implemented and I don't feel strong enough in Ruby to implement that there and then using it here.)

ericraio commented 1 year ago

@gdubicki thanks for your comment, I realized that I did not hit the save button on the ssh key in the dashboard, looks like we need a timeout as this is suggesting

FranckRnt commented 1 year ago

Hello to all, I found a workaround for the connection to be established, I had to set the variable override.ssh.host with an IP address.

I saw that this value was not filled in after running a vagrant up --debug.

For the moment I set the ip in hard because I haven't found a way to do it with a variable or dynamically

below the code :

Vagrant.configure("2") do |config|
  config.vm.box = "gce"

  config.vm.provider :google do |google, override|
    google.google_project_id = "your-project-id"
    google.google_json_key_location = "cred.json"
    google.image_family = 'rocky-linux-9'
    google.image_project_id = 'rocky-linux-cloud'
    google.name = "develvagrant"
    google.zone = "europe-west4-a"
    google.machine_type = "n2-standard-2"
    google.disk_size = 30
    google.network = 'lz-network'
    google.subnetwork = 'lz-subnetwork-eemshaven'
    google.external_ip = false
    google.tags = ['internet', 'ssh', 'europe-west-4']
    google.network_ip = '1.2.3.4'
    override.ssh.host = '1.2.3.4'
    override.ssh.username = "tstvagrantfrt"
    override.ssh.private_key_path = "id_rsa"
  end

end