Skip to content

Conversation

victormlg
Copy link
Contributor

It was a bit hard to know exactly what approach to take so if you have any better ideas I am interested

This doesn't exactly work yet, because

  • when creating VMs in a loop with a default name (like dev-1, dev-2, dev-3...) , the vms are created but only the first one created is accessible from the directory where lies the Vagrantfile (I'm using virtualbox)
  • when creating VMs with a custom name given by an env variable (ike in the pr) the vm is just not accessible, as if it wasn't created, but is actually present in virtualbox.

I am not sure how we should provision the created vms. We could:

  • just leave them unprovisioned
  • like I do in the code: let the user input his own provision script
  • start the VM unprovisioned, then inspect it using nt-discovery.sh and find all the information we need (like what package manager it uses, etc...) then provision it with a modular script using the collected data.

Ticket: ENT-5725
Signed-off-by: Victor Moene <[email protected]>
# https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session#Upgrade.2Fcompatibility_impact
v.qemu_use_session = false
override.vm.synced_folder "./", "/vagrant", type: :rsync
override.vm.synced_folder "#{NTECH_ROOT}", "/northern.tech", type: :rsync
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably should not sync the NTECH folder?

Copy link
Contributor

@craigcomstock craigcomstock left a comment

Choose a reason for hiding this comment

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

looks like a great start! I have added some notes on things we have solved in jenkins-vms regarding various bits.

VM_BOX="ubuntu/focal64"
end

if ENV['VM_COUNT']
Copy link
Contributor

Choose a reason for hiding this comment

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

This is where your problem lies when you try to do "vagrant" commands in the directory. The ENV vars won't be there so you will only have 1 vm.

The same goes for the other ENV variables... they should likely instead be set in a file to include like:

https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/scripts/common.rb?ref_type=heads#L35

config_path = File.expand_path("../../" + Socket.gethostname + ".yaml", __FILE__)

Variables could also be set in the Vagrantfile itself and then for cf-remote you could make a "common.rb" like jenkins-vms does: https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/machines/centos-7-x64/Vagrantfile?ref_type=heads

BOX="centos/7"
require File.expand_path("../../../scripts/common.rb", __FILE__)

node.vm.provider "virtualbox" do |vb|
vb.memory = VM_MEMORY
vb.cpus = VM_CPUS
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
Copy link
Contributor

Choose a reason for hiding this comment

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

regarding time and dns you might need to include this snippet from jenkins-vms that handles darwin/macos

https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/scripts/common.rb?ref_type=heads#L104

# previously working Vagrantfiles:
# https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session#Upgrade.2Fcompatibility_impact
v.qemu_use_session = false
override.vm.synced_folder "./", "/vagrant", type: :rsync
Copy link
Contributor

Choose a reason for hiding this comment

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

synced folders are also tricky for older distributions like debian-9:

here are some workarounds for centos-7 and old debians:

https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/scripts/common.rb?ref_type=heads#L151

type=str,
)
sp.add_argument(
"--provision", help="full path to provision script for Vagrant VM", type=str
Copy link
Contributor

Choose a reason for hiding this comment

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

you might clarify that this is expected to be a shell script right?

Comment on lines +743 to +756
vagrant_env["VAGRANT_CWD"] = vagrantdir
vagrant_env["VM_BOX"] = box
vagrant_env["VM_COUNT"] = str(count)
vagrant_env["VM_NAME"] = name
if sync_root:
vagrant_env["NTECH_ROOT"] = sync_root
if cpus:
vagrant_env["VM_CPUS"] = str(cpus)
if memory:
vagrant_env["VM_MEMORY"] = str(memory)
if provision:
vagrant_env["VM_PROVISION"] = filename
else:
command_args.append("--no-provision")
Copy link
Contributor

Choose a reason for hiding this comment

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

these environment items are what I think you should write into a file in the directory for this set of VMs and read from there in the Vagrantfile. That way the environment when used manually is the same and your number of vms, etc will be preserved.

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

Successfully merging this pull request may close these issues.

3 participants