Discussion: Proxmox + Ansible = Awesomeness

Feb 25, 2024
105
18
18
Hey guys, i am an ansible enthusisast and would like to start a discussion on your usecase and my usecase regarding ansible. I am not an ansible expert but I love utilizing ansible as much as possible. Maybe I can get some ideas and you can get some ideas from me. So here it is:

I have a vm which iis running ansible and ansble awx to automate tasks that are done over and over. After setting everything up you can save a lot of time. Like really a lot :) Here's how utilize ansible:
  • automate backups of lxc and vms
  • automate update
  • automate lxc and vm deployment
  • wake up truenas scale backup server via WOL and then start replication then shut it down when it's done to save energy
  • automate unlocking of dataset because i use passphrase for many dataset for security. (you know when HW got stolen all data is locked down)
  • automate installation of packages
  • shutdown groups of vm/lxc before truenas update then start them after update
  • etc.
For a couple vm this might not be worth it but worth learning. When my homelab started getting bigger the time I spend doing stuff over and over and doing them to ech vm/lxc was just immense and now I can do garden work again lol

How do you use ansible?
 
@Alwin Antreich Thanks for the inout! :) No i have not tried that one yet. I've always wanted to try cloud-init but never done it :p It's on my to do list though :) Sounds like you use Proxmox in the company with ansible. Do you have more ideas or suggestions for me as a homelaber?
 
Nice to hear you're having fun. Have you tried utilizing cloud-init with ansible-pull yet?
Well, cloud-init alone can automate the initial installation of the VM and ansible gets the rest done. We use it in our infra. :)
I'm in the process of trying to build a playbook that I run locally (and in the future from AWX with a Survey to change the VMName and VMID) that uses a cloud-init image to fully deploy a "current" OS that is ready to add "roles" to. I seem to be seeing a lot of "plays" that run directly on the PVE host. Do you have a link or a playbook to share that will accomplish this remotely?
 
I'm boring. I just use it to keep my proxmox nodes, VMs and LXCs up to date, to reboot when a new kernel is installed and to run apt autoremove as needed.
 
i use ansible to install okd and all the components needed for the install on proxmox, which contains setting up dns dhcp tftp server with all necesarry prerequisites and then bootstraps a full okd install via UPI

okd does some way of cloud init, so i do cloud init, but not via the proxmox ui

but till yet i do not use ansible to update proxmox itself, which sounds like a good idea to implement :)
 
Last edited:
Isn't unattended-upgrade doing this already? Never used ansible to update stuff.
Yes, I could do it that way. I could also do it with a shell script. But, with Ansible, I learned a new skill, I can trigger an automatic reboot after a new kernel install and I can automatically remove unused kernels. Plus I can extend it to do other tasks for me in the future.
 
  • Like
Reactions: homelabenthusiast
In Ansible your imagination is the limit :p It is just very powerful that you can also wipe your entire homelab if not done correctly :p
That's true for any programming language I ever worked with and still true for the good old shell. Ansible is nice, yet it wasn't the first and it won't be the last automation technology. Depending on the problem, I still use shell very often.
 
Yes, I could do it that way. I could also do it with a shell script. But, with Ansible, I learned a new skill, I can trigger an automatic reboot after a new kernel install and I can automatically remove unused kernels. Plus I can extend it to do other tasks for me in the future.
Would you mind sharing how you trigger an automatic reboot after a new kernel install and then automatically remove unused kernels?
 
Would you mind sharing how you trigger an automatic reboot after a new kernel install and then automatically remove unused kernels?
Automatic reboots of your hypervisor? Have a lot of fun with that ;)

After installing a new kernel, the file /var/run/reboot-required is created, so that you know you need to reboot. Kernels are automatically removed if there are more than 2 kernels in your current kernel version bracket. Removing a previous kernel bracket has to be done manually and should also be considered carefully. There has been reports about problems with with the newer kernel line, so blindly removing stuff is NEVER a good idea.
 
Automatic reboots of your hypervisor? Have a lot of fun with that ;)

After installing a new kernel, the file /var/run/reboot-required is created, so that you know you need to reboot. Kernels are automatically removed if there are more than 2 kernels in your current kernel version bracket. Removing a previous kernel bracket has to be done manually and should also be considered carefully. There has been reports about problems with with the newer kernel line, so blindly removing stuff is NEVER a good idea.
Thank you. Great, I didn't know about the reboot-required file. Just experimenting with some automations for my home lab. Should the automatic reboot fail, that is not an issue in this environment.
 
Hey guys, i am an ansible enthusisast and would like to start a discussion on your usecase and my usecase regarding ansible. I am not an ansible expert but I love utilizing ansible as much as possible. Maybe I can get some ideas and you can get some ideas from me. So here it is:

I have a vm which iis running ansible and ansble awx to automate tasks that are done over and over. After setting everything up you can save a lot of time. Like really a lot :) Here's how utilize ansible:
  • automate backups of lxc and vms
  • automate update
  • automate lxc and vm deployment
  • wake up truenas scale backup server via WOL and then start replication then shut it down when it's done to save energy
  • automate unlocking of dataset because i use passphrase for many dataset for security. (you know when HW got stolen all data is locked down)
  • automate installation of packages
  • shutdown groups of vm/lxc before truenas update then start them after update
  • etc.
For a couple vm this might not be worth it but worth learning. When my homelab started getting bigger the time I spend doing stuff over and over and doing them to ech vm/lxc was just immense and now I can do garden work again lol

How do you use ansible?
Hi, nice to hear that, you are right ansible is really useful, but imo more plugins can be imlpemented to Ansible Community general collectiion for improve the Proxmox configuration as code. With that said e.g. network creation, dns configuration.. There are good existant plugins https://docs.ansible.com/ansible/latest/collections/community/general/ but it could be improve, because at the moment the configuration I made was using Terraform. :):)
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!