Faster way to provision Debian KVM Virtual Machines?

I find that I’m often repeating myself and wasting time creating the same virtual machines over and over again, and would like to know if there’s a faster way to deploy vm’s?

I would like to be able to run a single command to provision a machine automatically as follows:

  1. Pick an OS (Debian 10.5)
  2. Attach network bridge br0, with a randomly generated MAC
  3. Assign a static IP address to the interface, provided in the provision command.
  4. Drop a custom bashrc in root and in username’s home.
  5. Add username, install sudo package, and username to sudo group
  6. set root and username password.
  7. Drop authorized_keys into the root/username .ssh folders
  8. Install any packages specified in a package list.
  9. Run updates.
  10. Set hostname, nameservers, etc, customize resolv.conf

I’ve tried creating a base install by hand and copying, the image, but there’s always problems. Lately, with the UEFI VM firmware, dding images seems to break them. Besides, it’s always annoying when you need to modify your base image, and it’s not really setup as a vm, etc. (what do you mean rsync isn’t installed by default!?)

So I know that Debian has automated install scripts, but I’m not sure how great that works (some sites say it doesn’t work well).

I’d really like to be able to do something like:

 # make-debian-web-server  --ip=192.168.1.1 --hostname=server0
 # ssh 192.168.1.1

And have it “just work” because the IP is set, my key pairs are loaded, and all other options have been set.

Thoughts?

Ansible.

1 Like

Or Vagrant. That’s the other one I hear talked about most often for this sort of thing.

1 Like

lxd and multipass if you want a gui

I’m sure you can create customized images for both of them, and lxd supports something called profiles, I’m not sure if multipass has this feature.

Yes, I know lxd is for managing containers (a wrapper around lxc) BUT for some reason canonical made lxd capable of manging KVM virtual machines… I don’t know why this feature is in lxd :man_shrugging:

Also I think I’ve never got networking for VMs created using lxd working on my archlinux installation… if anyone is willing to test it on their system, please let me know if it works for you.

2 Likes

Looks like that is for people with money. :slight_smile:

Need to investigate more. Thanks for suggestions, I had a motherboard failure on the desktop and RAID issues on the NFS server consume the week.

There’s also an option for making custom images with preseed, but not sure how well it works. And it wouldn’t add all the stuff I do after the install.

No, Ansible is free and is in pretty much every distro’s repo. Just Ansible Tower is $$.

I have only a little experience with Ansible. I though it is only useable from the point where I have SSH access to the machine. Are you sure you can provision a virtual machine from the host and set it up or how would the process look like in that case?

You’d use vagrant or whatever to install the vm and give it an ip address and make sure it had an admin user with ssh ability.

Then use ansible to install and configure it for the role you want to give it.

There’s lots of videos that can explain it way better than me. :smiley:

2 Likes

Thank you very much. This small Youtube channel is excellent. I did not know about Vagrant, but I guess now I have something to do in the next weeks.

1 Like

There’s a free version (never used either though).

Also, this is how to automate a Debian installation. Not sure how to hook an arbitrary script into it but I’m sure it’s possible.

https://wiki.debian.org/DebianInstaller/Preseed