DEV Community

DanLin
DanLin

Posted on

How I Learned IaC Without Losing My Mind 🤯

Prologue: The Quest for IaC Experience

I decided to prepare for an SRE/DevOps internship and learn Infrastructure as Code.

The challenge: build a portfolio project demonstrating IaC skills, but without using clouds or paid VPS — student budget is tight, and I don't trust those “free trials” that suddenly turn into bills.

I asked AI assistants for advice and got:

"Use Vagrant + Ansible + Terraform!"

Sounded impressive. In practice… well, let's just say it was an adventure.


Chapter 1: The Rise and Fall of Vagrant

Installed Vagrant on my CachyOS and added plugins as recommended by Arch Wiki.

Created a basic Vagrantfile — what could possibly go wrong?

Error #1: The Ghost of Plugins Past

undefined method 'exists?' for class File (NoMethodError)
path && File.exists?(path)
Enter fullscreen mode Exit fullscreen mode

The vagrant-vbguest plugin had been abandoned since 2023 and was incompatible with modern Ruby.
The solution was surprisingly simple:

config.vbguest.auto_update = false
Enter fullscreen mode Exit fullscreen mode

After some ritual dancing, the VM finally booted! 🥳


Chapter 2: Terraform and the Over-engineering Trap

Next phase: two VMs via Terraform + Ansible configuration.
This is where the real fun began:

  • Ansible installed Docker, Prometheus, and Grafana on both VMs — why?
  • Docker-ce refused to install due to dependency hell
  • At some point Ansible just froze without explanation

The most ironic moment: after hours of struggle, the AI assistant finally declared:

"Vagrant is legacy crap, just drop it"

I felt like a character in Harlan Ellison's “I Have No Mouth, and I Must Scream” — trapped in a digital nightmare of my own making. 🤡


Chapter 3: Monitron and the Golden Screwdriver

I decided to improve my existing Monitron project (a monitoring stack in Docker Compose) by adding Ansible.
The AI insisted: “This will give you idempotency and portability!”

In practice, I got a playbook that… copied files and ran docker-compose up.
Ansible became a golden screwdriver for a simple task.


Chapter 4: The PostgreSQL Wars

In my final attempt to create ansible-lab, I faced epic PostgreSQL battles:

Permission Error

chmod: invalid mode: 'A+user:postgres:rx:allow'
Enter fullscreen mode Exit fullscreen mode

Authentication Nightmare

FATAL: Peer authentication failed for user "postgres"
Enter fullscreen mode Exit fullscreen mode

The AI suggested everything — installing extra collections, solving non-existent permission issues, and even thought I was on Windows!

The solution turned out to be laughably simple — replace complex modules with shell commands:

- name: Create PostgreSQL user
  command: sudo -u postgres psql -c "CREATE USER myapp_user WITH PASSWORD 'secret';"
Enter fullscreen mode Exit fullscreen mode

And miracle of miracles — it worked on the first try!


Epilogue: ansible-lab and Lessons Learned

I finally built a working pet project:

  • Vagrant creates two VMs (db + app)
  • Ansible manages them via roles
  • No Terraform, no unnecessary complexity

Lessons Learned:

  1. Trust, but Verify AI assistants are tools, not gurus. Always ask:

"Why do I need this technology for my specific use case?"

  1. Ansible Without VMs is Over-engineering
    Use Bash for your local machine, Docker for containers.
    Ansible shines when you have multiple servers to manage.

  2. Sometimes Simple is Better
    My final solution was simpler than the original plans, but it actually works and demonstrates exactly what I needed.

  3. Real Experience > Perfect Tutorials
    In interviews, real problem-solving stories are valued more than memorized syntax.

💡 Advice for Beginners:
Start with small but working projects. Sometimes a simple Vagrant lab is more valuable than a complex "everything-but-the-kitchen-sink" setup.


P.S. Dear AI assistants, I still love you. But sometimes you're absolute trolls. 😄

👉 Check out my ansible-lab on GitHub

Top comments (0)