vagrant-google icon indicating copy to clipboard operation
vagrant-google copied to clipboard

SSH never times out

Open Temikus opened this issue 5 years ago • 3 comments

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.

Temikus avatar Feb 21 '20 01:02 Temikus

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.)

gdubicki avatar Dec 26 '21 12:12 gdubicki

@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

ericraio avatar Oct 11 '22 21:10 ericraio

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

FranckRnt avatar Mar 07 '23 09:03 FranckRnt