Howdy!
Picture this: you’re standing in your lab - cables everywhere, the faint hum of spinning drives, and machines scattered across your network like confused Pokémon. Each one needs users, SSH keys, updates, tweaks, configs, maybe even a sprinkle of “please just work” magic.
Doing all that by hand? I’ve been there and..No thanks.
Enter Ansible, a tool that I’ve discovered too late and lets you automate your infrastructure using nothing more than YAML, SSH, and pure hope. No agents, no daemons, no dark rituals (maybe just a couple of swear words in the middle of the night) - just commands flying through the network like tiny obedient drones. It’s simple, it’s powerful, and it’s perfect for a homelab where you want consistency without spending three nights configuring six VMs manually.
Think of Ansible as Doc Brown with a wrench and a clipboard: excited, with a bad sense of humor, but absolutely here to simplify your life.
Let’s have a walkthrough of what I did, so you won’t have to curse as much!
⚙️ Step 1: Preparing the Lab
Before you can deploy your glorious fleet of automation, every machine needs:
- a user (usually the one who’ll run Ansible)
- SSH access (with keys)
- Passwordless sudo (optional in production, convenient in homelabs)
👤Step 2: Creating the User
On each VM:
sudo adduser droid
sudo usermod -aG sudo droid
This gives you a friendly Ansible-capable user.
🔐 Step 3: Enabling Root Login Temporarily (Homelab Only!)
Sometimes you need to log in as root once to install your SSH key. For a homelab, that’s fine.
Edit:
sudo nano /etc/ssh/sshd_config
Set:
PermitRootLogin yes
PasswordAuthentication yes
Restart SSH:
sudo systemctl restart sshd
Now you can log in as root, drop your SSH key, and proceed.
After you’re done, turn this back off:
PermitRootLogin prohibit-password
PasswordAuthentication no
🗝️ Step 4: Copying Your SSH Key
From your Ansible controller:
ssh-copy-id droid@VM-IP
Boom - key installed.
🔓 Step 5: Passwordless Sudo (Homelab Convenience Mode)
If you want Ansible to run sudo commands without prompting for a password, edit sudoers safely:
sudo visudo
Add:
droid ALL=(ALL) NOPASSWD:ALL
⚠️ Note: this must be exactly ALL, not All, not aLl - sudo has no chill.
And in production?
Don’t do global NOPASSWD. Instead:
- restrict commands your automation user can run
- use
sudo -lto verify minimal privileges - prefer Ansible become passwords stored in Vault
- require MFA or hardware tokens for SSH
- never allow root login
Basically: keep the Flux Capacitor locked behind blast doors.
🔍 Step 6: Finding the Assigned IP
On Ubuntu:
ip a
Or the shorter:
hostname -I
Or the friendliest:
nmcli device show | grep IP4.ADDRESS
Considerations
With users ready, SSH keys installed, and sudo tamed, your machines are now prepared to be orchestrated like a symphony of slightly confused robots.
This whole setup paves the way for the real adventure: using Ansible to configure your fleet, deploy services, and - in a future episode - start harvesting metrics like a mad scientist.
Stay tuned for Part 2, where we plug our newly prepared nodes into the automation engine and watch the magic happen… with just a hint of controlled chaos.
Happy building ⚒