Hi, got Proxmox installed. Now want to install some VMs but would like to use a simple setup rather than painfully going trough an install. I’ve read I could accomplish this via ansible. Are there ready playbooks you can hack? Presumably I would need to have Proxmox understand playbooks?
Oversimplifying it, Ansible playbooks are nothing more than some commands that should be run on a remote machine via ssh. Ansible knows or has modules for a variety of different package managers (apt, yum, etc) and automagically knows how to handle services or various config files.
It can get complex, but I think just the startup phase, until you have an inventory of remote machines, the ssh keys are in place, etc. I second the Jeff Geerling recommendation, his stuff is solid, both ready to use playbooks, and tutorials.
I would suggest to also look into
cloudinit
. Makes setting up VMs on proxmox easier, faster, more consistent, with users, networking, ssh keys, etc ready to use (by you or by Ansible).Check out NixOS. It can build qcow images from scratch for you to import into proxmox
https://github.com/nix-community/nixos-generators
I have 8 bare-metal servers and I do everything automated with NixOS, I rarely ever access the servers directly.
Here are the nixos configs for my DHCP server and kubernetes servers that you can use as a base.
https://codeberg.org/jlh/h5b/src/branch/main/porygonz
https://codeberg.org/jlh/h5b/src/branch/main/nodes
For what it’s worth, Ive been using Ansible off and on at work for 8 years, and I think it’s pretty outdated and clunky these days, there are much smarter ways to manage workloads such as kubernetes, cloud-init, terraform, and NixOS. If you don’t want to get into Kubernetes then definitely learn NixOS.
I’d recommend using OpenTofu (Terraform) for initial provisioning of VMs and then use Ansible for post-provisioning config & management. That way you’re letting both tools play to their strengths.
https://registry.terraform.io/providers/bpg/proxmox/latest/docs
Besides ansible, also have a look at “templates” and “cloud-init” for VM generation.
I personally would avoid Cloud init as it is largely a Ubuntu thing.
Instead look into Flatcar or bootable containers
It works on debian too, which of course is ubuntu’s base distro. Just adding info.
You also could just use Ansible
Cloud init adds overhead to a clean Debian install. I’ve never really liked it personally.
Please, for the love of god, look at other things instead of Ansible.
Definitely do openTofu for infrastructure and deployment, but for configuration of VMs please learn about puppet, saltstack, chef(cinc.sh) and especially mgmtConfig .
Ansible, by comparison, better matches what we were doing in 2002 at 1/10th the speed, and it’s like pascal levels of wordy.
Learning about options and finding one that works well for you will often give you a much better experience than fucking Ansible.
If you do abandon all hope, though, then go ahead and do Ansible; but remember if you do: there are better options, and hating Ansible doesn’t mean you hate automation.
Sounds like you are looking for Opentofu/Terraform. I use Opentofu to fastly create VMs on Proxmox with Cloud Init scripts. In scenario where one VM hosts one service I try to build IaC that way I can destroy VM and create a new one without loosing anything, data nor configuration.
If you needs are simple, write a simple playbook using the proxmox ansible module https://docs.ansible.com/ansible/latest/collections/community/general/proxmox_kvm_module.html
Terraform/Opentofu provides more advanced stuff but then you have to worry about persistent state storage, the clunky DSL… used it when acsolutely needed, you can do 90% of this stuff with the proxmox ansible module.
If you need to make your playbook less verbose, move the logic to a role so that you can configure your VMs from a few lines in the playbook/host_vars. Mine looks like this (it’s for libvirt and not proxmox, but the logic is the same)
# playbook.yml - hosts: hypervisor.example.org roles: - libvirt # host_vars/hypervisor.example.org.yml libvirt_vms: - name: vm1.example.org xml_file: "{{ playbook_dir }}/data/libvirt/vm1.example.org.xml" state: running autostart: yes - name: vm2.example.org xml_file: "{{ playbook_dir }}/data/libvirt/vm2.example.org.xml" autostart: no - name: vm3.example.org xml_file: "{{ playbook_dir }}/data/libvirt/vm3.example.org.xml" autostart: no - name: vm4.example.org xml_file: "{{ playbook_dir }}/data/libvirt/vm4.example.org.xml" autostart: no disk_size: 100G
Hello you maybe best do some reading up on how ansible works, as it can get very complex.
This might be a good sting point 👉 https://www.jeffgeerling.com/project/ansible-101-youtube-series