Introduction
Managing a homelab can be time-consuming, especially as the number of virtual machines grows. To make the process more efficient, I used Ansible to automate key maintenance tasks across my Proxmox VMs.
This post outlines how I installed Ansible on Windows 11, set up secure SSH access to my VMs, and created a playbook to handle routine system upkeep.
Setup Process
Installing Ansible on Windows 11
To begin, I installed Ansible using WSL and pip. This allowed me to run Ansible from my Windows machine using a Linux environment.
Setting Up SSH Access
Next, I created SSH keys and copied them to each of my six Proxmox-based virtual machines. This allows passwordless access, which is essential for seamless automation.
Ansible Inventory File
I defined all my VM IPs in a simple inventory file to group them together:
[proxmox_vms]
192.168.1.101
192.168.1.102
192.168.1.103
192.168.1.104
192.168.1.105
192.168.1.106
Maintenance Playbook
Here’s an example of an Ansible playbook I created to manage routine maintenance across all VMs:
---
- name: Maintain all Proxmox VMs
hosts: proxmox_vms
become: yes
tasks:
- name: Update packages and cache
apt:
update_cache: yes
upgrade: dist
- name: Remove unused dependencies
apt:
autoremove: yes
- name: Clean system cache
shell: apt-get clean
- name: Rotate logs
command: logrotate /etc/logrotate.conf
- name: Check for failed services
command: systemctl --failed
register: failed_services
- name: Display failed services if any
debug:
var: failed_services.stdout_lines
Results and Observations
Automating these tasks helped me reduce the time spent on manual maintenance and ensured consistent system performance across all machines. With the playbook in place, I can now run regular updates and checks with a single command.
Conclusion
Using Ansible to manage my Proxmox homelab has made system administration faster, cleaner, and more reliable. As my homelab grows, I plan to extend this setup to include service monitoring, alerting, and scheduled snapshots.
Sources: