?? Learning Ansible: A Journey with Multipass and Docker on a Mac ??
Syed Aizaz Z.
AWS Certified Solutions Architect | IREB? Certified Agile Requirements Engineer | Distributed Software Systems Masters TU Darmstadt
So, here's a little story for anyone diving into automation and infrastructure management!
Recently, I was setting up an environment to test out Ansible, and my goal was to create multiple Linux hosts quickly for practice and learning. Initially, I installed Multipass on my Mac, thinking it was the perfect solution. I wanted to spin up a few VMs, run my playbooks, and tear them down once I was done.
Here's what I did with Multipass:
Installed Multipass with Homebrew:
brew install multipass
Launched Multiple VMs:
for i in {1..3}; do
multipass launch --name vm$i;
done
But here’s where things went sideways! ??
After running these commands, I encountered some errors (time-out) with Multipass that prevented me from properly creating and managing the VMs. The Multipass is currently not working with the Mac Darwin OS.
At this point, I was stuck, and after spending too much time trying to troubleshoot, I realized I was making things harder than they needed to be.
The Solution: Docker! ??
I suddenly remembered I already had Docker installed on my Mac. Instead of wasting more time, I realized Docker would let me spin up lightweight Linux containers instantly.
By simply running a few Docker commands, I was able to create multiple Linux containers, configure them, and test my Ansible playbooks—all without the overhead of full virtual machines. And when I was done? A quick docker rm to clean up the environment. ??
领英推荐
Here’s how I did it with Docker:
Run Multiple Linux Containers:
docker run -d --name ubuntu1 ubuntu:latest sleep infinity
docker run -d --name ubuntu2 ubuntu:latest sleep infinity
docker run -d --name ubuntu3 ubuntu:latest sleep infinity
Check the IP Address of the Containers: Initially, I tried using ifconfig, ip addr to get the IP address, but the command wasn’t found. Instead, I used Docker's inspect command:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ubuntu1
Access Any Container:
docker exec -it ubuntu1 bash
Remove the Containers When Done:
docker stop ubuntu1 ubuntu2 ubuntu3
docker rm ubuntu1 ubuntu2 ubuntu3
?? Why Homebrew is Better for Installation? Using Homebrew to install software like Multipass offers several advantages:
?? Pro Tip: If you’re learning Ansible (or any other automation tools), Docker is a quick and easy way to set up multiple Linux hosts. No need to worry about virtualization overhead—just run, test, and delete when you’re done!
What started as a small hiccup with Multipass turned into a valuable realization with Docker. It’s all part of the learning process! ??
If you have a better solution, please let me know.
#Ansible #Docker #Automation #LearningByDoing #DevOpsJourney #TechLearning #Homebrew