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

DTT1 - Iteration 3 - Allocation module - Fix Vagrant inventory IP is always localhost #4874

Closed
2 tasks done
Tracked by #4855
QU3B1M opened this issue Jan 19, 2024 · 4 comments · Fixed by #4885
Closed
2 tasks done
Tracked by #4855
Assignees

Comments

@QU3B1M
Copy link
Member

QU3B1M commented Jan 19, 2024

Epic #4855

Description

This issue aims to fix the Vagrant provider retrieving always 127.0.0.1 as VM's IP, this problem occurs because vagrant ssh-config returns the default config.ssh values, a possible fix is to define config.ssh.host with the provider configured IP (check this guide).

Tasks

  • Research in the Vagrant docs how to properly configure VM's config.ssh.
  • Apply the solution and verify the inventory is usable by the rest of modules.
@QU3B1M
Copy link
Member Author

QU3B1M commented Jan 19, 2024

Extra info

Possible solution tested in a local Vagrantfile, the command vagrrant ssh-config retrieves the info required, but the vagrant up fails by timeout (the VM is turning on) and vagrant ssh won't connect to the machine.

Output of vagrant up with error:

vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'generic/ubuntu2004'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'generic/ubuntu2004' version '4.3.8' is up to date...
==> default: Setting the name of the VM: test_default_1705674568055_3441
==> default: Fixed port collision for 22 => 2222. Now on port 2201.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2201 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 192.168.57.3:2201
    default: SSH username: vagrant
    default: SSH auth method: private key
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

@QU3B1M
Copy link
Member Author

QU3B1M commented Jan 23, 2024

Update report

After some research and testing we found that in order to do the desired configuration, we need to manually set every ssh option for the machine, including the guest and host ports on the Vagrantfile using config.ssh. Anyway, with that configuration we accomplish one successful execution and then the errors start over.

Continuing with the research.

@QU3B1M
Copy link
Member Author

QU3B1M commented Jan 26, 2024

Update report

It was not possible to configure the host on Vagrant's config.ssh in the first boot of the VM, this is because Vagrant configures the networks after the first connection attempt to the machines.

Solution

As the connection using the host configured in Vagrant's config.ssh could be done after the second connection, and in our module, we are already restarting the VM after the creation, I added some Ruby code to generate an initialization indicator (a file), if that indicator exists when the VM is being started/restarted (meaning this is not the first time the machine is up), it will use the configuration from config.ssh, in the other case, it will use the Vagrant defaults (being the initial boot). The added code is the following

  init_indicator = "./init"
  if not ::File.exists?(init_indicator)
      File.write(init_indicator, "initialized")
  else
      # Use the IP address of the VM to connect via SSH
      config.ssh.host = "{{ config.ip }}"
      config.ssh.port = 22
      config.ssh.private_key_path = "{{ config.private_key }}"
  end

It is not a great solution, maybe a better way could be found with some more research, especially in the VBoxManage documentation and how to apply it in the vagrantfile.

@QU3B1M QU3B1M linked a pull request Jan 26, 2024 that will close this issue
2 tasks
@pro-akim
Copy link
Member

Review Notes

Tests 🟢
LGTM

@fcaffieri fcaffieri added level/task Task issue and removed level/subtask Subtask issue labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
4 participants