Vagrant set ssh hostname to match private IP fails

Viewed 173

I'm trying to bring up 2 Vagrant VMs via a single Vagrantfile. When I try to match the ssh hostname to the private IP of that VM, I get the following error:

Progress: 90%
==> controller: Matching MAC address for NAT networking...
==> controller: Checking if box 'fedora/32-cloud-base' version '32.20200422.0' is up to date...
==> controller: Setting the name of the VM: pki_controller_1597975375714_9403
==> controller: Clearing any previously set network interfaces...
==> controller: Preparing network interfaces based on configuration...
    controller: Adapter 1: nat
    controller: Adapter 2: hostonly
==> controller: Forwarding ports...
    controller: 22 (guest) => 2222 (host) (adapter 1)
==> controller: Running 'pre-boot' VM customizations...
==> controller: Booting VM...
==> controller: Waiting for machine to boot. This may take a few minutes...
    controller: SSH address: 192.168.33.10:22
    controller: SSH username: root
    controller: SSH auth method: private key
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...
    controller: Warning: Host appears down. Retrying...

While it kept retrying, I tried to ping 192.168.33.10 and I received this response:

$ ping 192.168.33.10
PING 192.168.33.10 (192.168.33.10) 56(84) bytes of data.
From 192.168.33.1 icmp_seq=1 Destination Host Unreachable   #   <-- NOTE THIS!
From 192.168.33.1 icmp_seq=2 Destination Host Unreachable
From 192.168.33.1 icmp_seq=3 Destination Host Unreachable

$ ifconfig
vboxnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.33.1  netmask 255.255.255.0  broadcast 192.168.33.255
        inet6 fe80::800:27ff:fe00:1  prefixlen 64  scopeid 0x20<link>
        ether 0a:00:27:00:00:01  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1094  bytes 78483 (76.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ traceroute 192.168.33.10
traceroute to 192.168.33.10 (192.168.33.10), 30 hops max, 60 byte packets
 1  localhost.localdomain (192.168.33.1)  1010.646 ms !H  1010.583 ms !H  1010.538 ms !H

Following are the contents of my Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.ssh.username = "root"
  config.vm.box = "fedora/32-cloud-base"
  config.vm.synced_folder "./", "/vagrant"
  config.ssh.port = 22                       # ENABLE ONLY IF ssh.host is specified  

  config.vm.provider :virtualbox do |domain, override|
    # Defaults for masters and clone
    # WARNING: Do not overcommit CPUs, it causes issues during
    # provisioning, when RPMs are installed
    domain.cpus = 1
    domain.memory = 2750

  end

  config.vm.define "controller" , primary: true do |controller|
    config.vm.provider :virtualbox do |domain, override|
      # Less resources needed for controller
      domain.memory = 950
    end
    controller.vm.provision "shell", inline: "pip3 install pyyaml && pip3 install -r /vagrant/path/to/requirements.txt"
    controller.vm.provision :ansible do |ansible|
      # Disable default limit to connect to all the machines
      ansible.limit = "all"
      ansible.playbook = "path/to/playbook.yml"
      ansible.groups = {
        "localhost" => ["controller"],
        "master" => ["master"]
      }
    end

    controller.vm.network :private_network, ip: "192.168.33.10"
    controller.ssh.host = "192.168.33.10"                       # DOES NOT WORK
  end


  config.vm.define "master"  do |master|
    master.vm.network :private_network, ip: "192.168.33.20"
    master.ssh.host = "192.168.33.20"                # DOES NOT WORK
  end

end

If I comment the *.ssh.host and try to ssh root@<ip> -i <path to private key>, it works. I am sure that I'm making a very minor mistake. But, I am not able to pin it down.

0 Answers
Related