Hands-on with Playbooks – Practice Makes Pro! 🧪⚙️

Welcome to Part 3.5 of our DevOps journey! You’ve made it through playbooks, modules, tasks, and YAML—amazing progress. Now, it’s time to put all that knowledge to the test. This part is all about exercises—small but practical tasks you can try out in your local lab setup (remember, the Docker-based one we created earlier).

Ready? Let’s go 💪


📝 Exercise 1: Ping Only Web Servers 🔍

Let’s say you have a group of web servers you want to check for connectivity.

  • Update your inventory file to include a new group [web] with node1 and node2.
  • Write a playbook that pings only the web group.

Why it matters: In the real world, you often target specific server roles (e.g., only web or database servers) instead of your entire fleet.

💡 Hint: Use hosts: web in your playbook.


📝 Exercise 2: Install Developer Tools 🧰

You want to prepare your managed nodes for software development. Create a playbook that:

  • Updates the APT cache
  • Installs curl, git, and vim

Why it matters: Prepping dev environments is a common Ansible use case.


📝 Exercise 3: Set Up a Demo User 👤

Imagine onboarding a new team member. Create a playbook that:

  • Adds a new user named demo
  • Creates their home directory
  • Ensures correct ownership and permissions

💡 Use the user and file modules

Why it matters: User provisioning is a classic and practical automation task.


🧪 Exercise 4: Create Multiple Directories Using a Loop 🔁

Push yourself a bit—create a playbook that sets up the following directories under /home/devuser/:

  • logs
  • configs
  • backups

Goal: Use a loop to avoid repeating the same task.

💡 Look into loop: or with_items: syntax. This one’s slightly ahead of what we’ve covered, so feel free to experiment or look it up!


🚀 Bonus Project: Provision a Simple NodeJS App 🧑‍🍳

Let’s simulate a real-world deployment! Create a playbook that:

  1. Installs nodejs and npm
  2. Clones a GitHub repo containing a Node.js app
  3. Installs app dependencies
  4. Sets up a systemd service to run the app
  5. Ensures the app is running and reachable

💡 Example project: Node.js Todo App – it’s simple, beginner-friendly, and a great candidate for automation!

Why this matters: Deploying an app is one of the best ways to test real-world automation skills. You’ll get a taste of web server setup, dependency management, service configuration, and remote code deployment—all in one go! Of course, there's a lot more to deployment than this, but it feels like a good start.


📬 Wrap-Up

These exercises are meant to reinforce everything we've covered so far—from inventory management to writing clean, effective playbooks. Try them out, tweak them, break them (safely), and most importantly: have fun!

When you're ready, we'll jump into Part 4 where we talk about variables, handlers, and conditional logic—aka making your playbooks smarter.

🚀 Keep going. You’re doing great!


Got stuck? Check the Ansible docs or drop your question in the comments section of any blog post. Let's learn together! 🙌