Skip to content

Load boxes.yaml and allow vagrant-hostmanager to update hypervisor#500

Open
ianballou wants to merge 1 commit into
theforeman:masterfrom
ianballou:Vagrantfile-hostmanager-configure-host
Open

Load boxes.yaml and allow vagrant-hostmanager to update hypervisor#500
ianballou wants to merge 1 commit into
theforeman:masterfrom
ianballou:Vagrantfile-hostmanager-configure-host

Conversation

@ianballou
Copy link
Copy Markdown

Why are you introducing these changes? (Problem description, related links)

What are the changes introduced in this pull request?

  • Adds hostmanager config, mainly so that the hypervisor's /etc/hosts is updated along with the VMs' hosts files.
  • Increases the dev box disk size to 50 to allow more space for long-lasting logs and Pulp.
  • Allows users to create a boxes.yaml file to add to the default box list in the Vagrantfile.

How to test this pull request

Steps to reproduce:

  • Try to create a boxes.yaml like
---
# User-local box definitions (this file is gitignored)
# Each entry becomes a vagrant box. Available settings:
#   box:       base box (default: centos/stream9)
#   hostname:  FQDN (default: <name>.example.com)
#   memory:    RAM in MB (default: 2048)
#   cpus:      CPU count (default: 1)
#   disk_size: disk in GB (default: unset)

katello-production:
  memory: 12288
  cpus: 4
  disk_size: 50
  • Try vagrant-hostmanager and ensure the hypervisor's hosts file is updated.

Checklist

  • Tests added/updated (if applicable)
  • Documentation updated (if applicable)

@ianballou
Copy link
Copy Markdown
Author

How do we want to advertise this boxes.yaml file? Docs?

Also this fixes #437

@ehelms
Copy link
Copy Markdown
Member

ehelms commented May 7, 2026

The failure was due to #497

Comment thread Vagrantfile
end
end

# Load user-local box definitions from boxes.yaml (gitignored)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminds me we should clean up the gitignore as it has some forklift-isms.

Copy link
Copy Markdown
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm never a fan of vagrant-hostmanager. Since #305 we configure the management network to have a DNS domain set so you actually have DNS between guests. The etc_hosts hack is no longer needed then.

The benefit is that it really works as a production system. Ruby's Resolv module famously has a line:

/etc/nsswitch.conf is not supported.

It may not be obvious, but glibc reads /etc/nsswitch.conf and if there's a files entry for hosts then it reads /etc/hosts. Foreman uses Resolv in some of its codebase, so

However, vagrant-libvirt only applies that to newly created networks so we should get people to migrate.

To also get the host to respond I use https://github.com/voxpupuli/setup-vagrant/blob/v0/network-hook to configure resolvectl. The only problem I have is that SELinux on my Fedora doesn't allow running Python for hooks. I think https://bugzilla.redhat.com/show_bug.cgi?id=2456505 is the same problem.

@ianballou
Copy link
Copy Markdown
Author

I'm never a fan of vagrant-hostmanager. Since #305 we configure the management network to have a DNS domain set so you actually have DNS between guests. The etc_hosts hack is no longer needed then.

The benefit is that it really works as a production system. Ruby's Resolv module famously has a line:

/etc/nsswitch.conf is not supported.

It may not be obvious, but glibc reads /etc/nsswitch.conf and if there's a files entry for hosts then it reads /etc/hosts. Foreman uses Resolv in some of its codebase, so

However, vagrant-libvirt only applies that to newly created networks so we should get people to migrate.

To also get the host to respond I use https://github.com/voxpupuli/setup-vagrant/blob/v0/network-hook to configure resolvectl. The only problem I have is that SELinux on my Fedora doesn't allow running Python for hooks. I think https://bugzilla.redhat.com/show_bug.cgi?id=2456505 is the same problem.

It's great to hear that we can rely on proper DNS between vagrant hosts. Having the hypervisor be able to connect to vagrant hosts is the more common issue (to me), so I'd like something 'official' for developers to follow. Do you think the network-hook that you mentioned could suit this? Whatever we end up going with, I'd like to have it in the developer documentation. If network-hook is a decent path forward, I'm happy to update the PR here to include a mention of it.

@ekohl
Copy link
Copy Markdown
Member

ekohl commented May 23, 2026

I found a solution to the SELinux issue and wrote up my notes in https://community.theforeman.org/t/setting-up-libvirt-with-dns-resolution-for-vagrant/46567.

Copy link
Copy Markdown
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to steer away from vagrant-hostmanager and direct to the DNS-based solution, but can see value in a boxes.yaml. Perhaps split it up?

Comment thread Vagrantfile
Comment on lines +54 to +55
user_boxes.each do |name, settings|
next if settings.nil?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
user_boxes.each do |name, settings|
next if settings.nil?
user_boxes.compact.each do |name, settings|

Comment thread Vagrantfile
user_boxes.each do |name, settings|
next if settings.nil?
config.vm.define name do |override|
override.vm.box = ENV.fetch("FOREMANCTL_BASE_BOX", settings.fetch('box', 'centos/stream9'))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the order be reversed and have the settings take priority?

Suggested change
override.vm.box = ENV.fetch("FOREMANCTL_BASE_BOX", settings.fetch('box', 'centos/stream9'))
override.vm.box = settings.fetch('box') { ENV.fetch('FOREMANCTL_BASE_BOX', 'centos/stream9') }

Comment thread Vagrantfile
next if settings.nil?
config.vm.define name do |override|
override.vm.box = ENV.fetch("FOREMANCTL_BASE_BOX", settings.fetch('box', 'centos/stream9'))
override.vm.hostname = settings.fetch('hostname', "#{name}.example.com")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you rebase, please respect the Vagrant domain here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants