-
Notifications
You must be signed in to change notification settings - Fork 20
ENT-5725: Added vagrant provider for spawning VMs #156
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
base: master
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this 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'] |
There was a problem hiding this comment.
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:
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 ] |
There was a problem hiding this comment.
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
# 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 |
There was a problem hiding this comment.
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:
type=str, | ||
) | ||
sp.add_argument( | ||
"--provision", help="full path to provision script for Vagrant VM", type=str |
There was a problem hiding this comment.
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?
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") |
There was a problem hiding this comment.
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.
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
I am not sure how we should provision the created vms. We could:
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.