<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Shehar Yar Khan</title>
    <description>The latest articles on DEV Community by Shehar Yar Khan (@sheharyar566).</description>
    <link>https://dev.to/sheharyar566</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1317651%2F5b9da4b9-a777-4e7a-af2f-d5196820f21f.png</url>
      <title>DEV Community: Shehar Yar Khan</title>
      <link>https://dev.to/sheharyar566</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sheharyar566"/>
    <language>en</language>
    <item>
      <title>A Beginner’s DevOps Journey – Starting with Ansible (Part 3.5)</title>
      <dc:creator>Shehar Yar Khan</dc:creator>
      <pubDate>Sun, 20 Apr 2025 17:48:09 +0000</pubDate>
      <link>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-35-3ilp</link>
      <guid>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-35-3ilp</guid>
      <description>&lt;h3&gt;
  
  
  &lt;em&gt;Hands-on with Playbooks – Practice Makes Pro!&lt;/em&gt; 🧪⚙️
&lt;/h3&gt;

&lt;p&gt;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).&lt;/p&gt;

&lt;p&gt;Ready? Let’s go 💪&lt;/p&gt;




&lt;h2&gt;
  
  
  📝 Exercise 1: Ping Only Web Servers 🔍
&lt;/h2&gt;

&lt;p&gt;Let’s say you have a group of web servers you want to check for connectivity.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update your inventory file to include a new group &lt;code&gt;[web]&lt;/code&gt; with &lt;code&gt;node1&lt;/code&gt; and &lt;code&gt;node2&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Write a playbook that pings only the &lt;code&gt;web&lt;/code&gt; group.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;blockquote&gt;
&lt;p&gt;💡 Hint: Use &lt;code&gt;hosts: web&lt;/code&gt; in your playbook.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  📝 Exercise 2: Install Developer Tools 🧰
&lt;/h2&gt;

&lt;p&gt;You want to prepare your managed nodes for software development. Create a playbook that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Updates the APT cache&lt;/li&gt;
&lt;li&gt;Installs &lt;code&gt;curl&lt;/code&gt;, &lt;code&gt;git&lt;/code&gt;, and &lt;code&gt;vim&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt; Prepping dev environments is a common Ansible use case.&lt;/p&gt;




&lt;h2&gt;
  
  
  📝 Exercise 3: Set Up a Demo User 👤
&lt;/h2&gt;

&lt;p&gt;Imagine onboarding a new team member. Create a playbook that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adds a new user named &lt;code&gt;demo&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Creates their home directory&lt;/li&gt;
&lt;li&gt;Ensures correct ownership and permissions&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Use the &lt;code&gt;user&lt;/code&gt; and &lt;code&gt;file&lt;/code&gt; modules&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Why it matters:&lt;/strong&gt; User provisioning is a classic and practical automation task.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Exercise 4: Create Multiple Directories Using a Loop 🔁
&lt;/h2&gt;

&lt;p&gt;Push yourself a bit—create a playbook that sets up the following directories under &lt;code&gt;/home/devuser/&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;logs&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;configs&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;backups&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Use a loop to avoid repeating the same task.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Look into &lt;code&gt;loop:&lt;/code&gt; or &lt;code&gt;with_items:&lt;/code&gt; syntax. This one’s slightly ahead of what we’ve covered, so feel free to experiment or look it up!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 Bonus Project: Provision a Simple NodeJS App 🧑‍🍳
&lt;/h2&gt;

&lt;p&gt;Let’s simulate a real-world deployment! Create a playbook that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Installs &lt;code&gt;nodejs&lt;/code&gt; and &lt;code&gt;npm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Clones a GitHub repo containing a Node.js app&lt;/li&gt;
&lt;li&gt;Installs app dependencies&lt;/li&gt;
&lt;li&gt;Sets up a systemd service to run the app&lt;/li&gt;
&lt;li&gt;Ensures the app is running and reachable&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Example project: &lt;a href="https://github.com/scotch-io/node-todo" rel="noopener noreferrer"&gt;Node.js Todo App&lt;/a&gt; – it’s simple, beginner-friendly, and a great candidate for automation!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Why this matters:&lt;/strong&gt; 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.&lt;/p&gt;




&lt;h2&gt;
  
  
  📬 Wrap-Up
&lt;/h2&gt;

&lt;p&gt;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!&lt;/p&gt;

&lt;p&gt;When you're ready, we'll jump into Part 4 where we talk about &lt;strong&gt;variables, handlers, and conditional logic&lt;/strong&gt;—aka making your playbooks smarter.&lt;/p&gt;

&lt;p&gt;🚀 Keep going. You’re doing great!&lt;/p&gt;




&lt;p&gt;Got stuck? Check the &lt;a href="https://docs.ansible.com/" rel="noopener noreferrer"&gt;Ansible docs&lt;/a&gt; or drop your question in the comments section of any blog post. Let's learn together! 🙌&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>beginners</category>
      <category>devops</category>
    </item>
    <item>
      <title>A Beginner’s DevOps Journey – Starting with Ansible (Part 3)</title>
      <dc:creator>Shehar Yar Khan</dc:creator>
      <pubDate>Sun, 20 Apr 2025 08:07:25 +0000</pubDate>
      <link>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-3-57ma</link>
      <guid>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-3-57ma</guid>
      <description>&lt;h3&gt;
  
  
  &lt;em&gt;Writing Your First Playbook + Understanding YAML&lt;/em&gt; ✍️📘
&lt;/h3&gt;




&lt;p&gt;Up to now, I’ve been flexing my Ansible muscles with ad-hoc commands. Handy for quick fixes, but let’s be honest—typing them over and over? Not ideal. This is where &lt;strong&gt;playbooks&lt;/strong&gt; step in to save the day. Think of them like scripts: reusable, organized, and a lot more powerful. If ad-hoc commands are like Post-it notes, playbooks are your bullet journal. 🗂️&lt;/p&gt;




&lt;h2&gt;
  
  
  📖 What is a Playbook?
&lt;/h2&gt;

&lt;p&gt;A playbook is a YAML file that tells Ansible what to do. It’s a list of plays, and each play targets a group of hosts and runs a series of tasks on them. Whether you’re installing packages, creating users, or spinning up services—playbooks are how you automate it.&lt;/p&gt;

&lt;p&gt;If you're familiar with &lt;code&gt;pubspec.yaml&lt;/code&gt; from Flutter or any YAML-based config (like GitHub Actions), this will feel comfortably familiar. 💡&lt;/p&gt;

&lt;p&gt;A basic playbook contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name&lt;/strong&gt; – A human-friendly label 🏷️&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hosts&lt;/strong&gt; – The machines you want to affect 🧑‍💻&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tasks&lt;/strong&gt; – The step-by-step jobs for Ansible to run ✅&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔧 Using &lt;code&gt;ansible.cfg&lt;/code&gt; to Simplify Things ⚙️
&lt;/h2&gt;

&lt;p&gt;One of the first things I did when starting out was to simplify my workflow. Typing &lt;code&gt;-i inventory&lt;/code&gt; and setting the key file every time gets old fast. Let’s fix that.&lt;/p&gt;

&lt;p&gt;Create an &lt;code&gt;ansible.cfg&lt;/code&gt; file in your project folder with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[defaults]&lt;/span&gt;
&lt;span class="py"&gt;inventory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;./inventory&lt;/span&gt;
&lt;span class="py"&gt;private_key_file&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;./ansible&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you don’t need to add &lt;code&gt;-i inventory&lt;/code&gt; or &lt;code&gt;--private-key&lt;/code&gt; to every command—Ansible will automatically know where to look. 🔍 It’s one of those tiny wins that make your life way easier.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 First Playbook: Ping All Nodes 🛎️
&lt;/h2&gt;

&lt;p&gt;Let’s ease into playbooks with a classic: the ping. This checks if our managed nodes are reachable.&lt;/p&gt;

&lt;p&gt;Create a file named &lt;code&gt;ping-nodes.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Ping all nodes&lt;/span&gt;
  &lt;span class="na"&gt;hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;all&lt;/span&gt;
  &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Check connectivity&lt;/span&gt;
      &lt;span class="na"&gt;ansible.builtin.ping&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible-playbook ping-nodes.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple, right? 🎉 You’ve just written and executed your first Ansible playbook!&lt;/p&gt;




&lt;h2&gt;
  
  
  🛠 Second Playbook: Perform Multiple Tasks 🧰
&lt;/h2&gt;

&lt;p&gt;Let’s get a little fancier. I wanted to try something a bit more involved—so I created a playbook that updates the system, installs a package, and creates a directory. Here’s how you can do it too.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;multi-task.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Multi-task playbook&lt;/span&gt;
  &lt;span class="na"&gt;hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;all&lt;/span&gt;
  &lt;span class="na"&gt;become&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;tasks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Update APT cache&lt;/span&gt;
      &lt;span class="na"&gt;apt&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;update_cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yes&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install curl&lt;/span&gt;
      &lt;span class="na"&gt;apt&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;curl&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;present&lt;/span&gt;

    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Create a directory&lt;/span&gt;
      &lt;span class="na"&gt;file&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/home/devuser/mydir&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;directory&lt;/span&gt;
        &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;0755'&lt;/span&gt;
        &lt;span class="na"&gt;owner&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;devuser&lt;/span&gt;
        &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;devuser&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this playbook does:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;🌀 Updates the package index&lt;/li&gt;
&lt;li&gt;📦 Installs &lt;code&gt;curl&lt;/code&gt; if it's not already installed&lt;/li&gt;
&lt;li&gt;📁 Creates a directory at &lt;code&gt;/home/devuser/mydir&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible-playbook multi-task.yml &lt;span class="nt"&gt;--ask-become-pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What’s that flag? ❓
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;become: true&lt;/code&gt;: Tells Ansible to run the tasks with elevated privileges (like &lt;code&gt;sudo&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--ask-become-pass&lt;/code&gt;: Prompts you to enter the password for privilege escalation 🔐&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pro tip: I always like to include &lt;code&gt;--ask-become-pass&lt;/code&gt; for these early setups—it keeps things secure and makes sure you’re aware when privilege escalation is in play.&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Explore Other Modules 🧭
&lt;/h2&gt;

&lt;p&gt;We’ve only scratched the surface. Here are some modules we used—and where you can learn more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🟢 &lt;a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ping_module.html" rel="noopener noreferrer"&gt;Ping&lt;/a&gt;: Test connectivity&lt;/li&gt;
&lt;li&gt;📦 &lt;a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html" rel="noopener noreferrer"&gt;APT&lt;/a&gt;: Manage packages on Debian-based systems&lt;/li&gt;
&lt;li&gt;📁 &lt;a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html" rel="noopener noreferrer"&gt;File&lt;/a&gt;: Create/remove files and directories&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whenever I'm unsure what a module can do—or what options it supports—the documentation is my go-to. Don’t hesitate to explore and experiment. 🧑‍🏫&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠ Common Pitfalls 🪤
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;YAML indentation&lt;/strong&gt;: Always use spaces (not tabs), and make sure things are aligned properly&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgetting &lt;code&gt;become: true&lt;/code&gt;&lt;/strong&gt;: Some actions (like installing packages) need elevated privileges. If they silently fail, this is likely why 😅&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Over-engineering too early&lt;/strong&gt;: Start simple. Grow later. 🌱&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 Try dry runs with &lt;code&gt;--check&lt;/code&gt; to preview what will happen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible-playbook multi-task.yml &lt;span class="nt"&gt;--check&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⏭ What’s Next? 🚀
&lt;/h2&gt;

&lt;p&gt;With basic playbooks under your belt, the doors to automation are officially open. You can now replicate tasks, share them, version them—welcome to scalable DevOps! 🤖&lt;/p&gt;

&lt;p&gt;In the next part, we’ll look at &lt;strong&gt;variables, conditionals, and handlers&lt;/strong&gt;—making your playbooks even more powerful and dynamic.&lt;/p&gt;

&lt;p&gt;Stay tuned. It only gets better from here ✨&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>docker</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Beginner’s DevOps Journey – Starting with Ansible (Part 2)</title>
      <dc:creator>Shehar Yar Khan</dc:creator>
      <pubDate>Tue, 15 Apr 2025 19:45:41 +0000</pubDate>
      <link>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-2-2afd</link>
      <guid>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-2-2afd</guid>
      <description>&lt;h3&gt;
  
  
  &lt;em&gt;Understanding the Basics + Running Your First Ad-Hoc Commands&lt;/em&gt;
&lt;/h3&gt;




&lt;p&gt;After writing &lt;a href="https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-1-4ke9"&gt;Part 1&lt;/a&gt;, I rolled up my sleeves and built a local lab using Docker containers. No virtual machines. No AWS. No billing surprises. Just a lightweight setup running entirely on my laptop. If you want to try the same, I wrote a quick guide here:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://dev.to/sheharyar566/build-a-local-ansible-lab-with-docker-no-vms-needed-1gf6"&gt;Build a Local Ansible Lab with Docker – No VMs Needed&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Of course, you can spin up EC2 instances or VMs if you prefer. The point is: get a few machines talking to each other. Once that's set up, the real fun begins.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This post is about that very first step — the “aha!” moment when you run your first Ansible command and &lt;em&gt;something actually happens&lt;/em&gt; on a remote machine.&lt;/p&gt;

&lt;p&gt;Here’s what we’re covering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How Ansible connects and talks to your nodes
&lt;/li&gt;
&lt;li&gt;What ad-hoc commands are and why they’re useful
&lt;/li&gt;
&lt;li&gt;A few real commands to run and see results instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No YAML, no playbooks — not yet. Just enough to build confidence and get comfortable.&lt;/p&gt;

&lt;p&gt;Let’s get started.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 A Few Basics Before We Get Hands-On
&lt;/h2&gt;

&lt;p&gt;Before we jump into typing Ansible commands like pros, let’s take a minute to peek under the hood — just enough to understand what’s actually happening when you run something.&lt;/p&gt;
&lt;h3&gt;
  
  
  🧱 The Control Node
&lt;/h3&gt;

&lt;p&gt;I’m using &lt;strong&gt;my laptop&lt;/strong&gt; as the control node. This is where Ansible lives. Think of it as the “brain” of the operation — issuing instructions to other machines, or in my case, containers.&lt;/p&gt;
&lt;h3&gt;
  
  
  🐳 The Managed Nodes (a.k.a. Docker Containers)
&lt;/h3&gt;

&lt;p&gt;I spun up &lt;strong&gt;three Ubuntu containers&lt;/strong&gt; on a custom Docker network named &lt;code&gt;ansible&lt;/code&gt;. No deep reason for the number three — I just wanted a small playground with a few machines to manage.&lt;/p&gt;


&lt;h2&gt;
  
  
  📄 Creating an Inventory File
&lt;/h2&gt;

&lt;p&gt;Now let’s teach Ansible &lt;em&gt;where&lt;/em&gt; to find our nodes — and &lt;em&gt;how&lt;/em&gt; to connect to them.&lt;/p&gt;

&lt;p&gt;I created a file named &lt;code&gt;inventory&lt;/code&gt; (but you can name it anything):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;inventory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And filled it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[nodes]&lt;/span&gt;
&lt;span class="err"&gt;node1&lt;/span&gt; &lt;span class="py"&gt;ansible_host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;localhost ansible_port=2221 ansible_user=devuser&lt;/span&gt;
&lt;span class="err"&gt;node2&lt;/span&gt; &lt;span class="py"&gt;ansible_host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;localhost ansible_port=2222 ansible_user=devuser&lt;/span&gt;
&lt;span class="err"&gt;node3&lt;/span&gt; &lt;span class="py"&gt;ansible_host&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;localhost ansible_port=2223 ansible_user=devuser&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we’re forwarding ports through localhost, this setup works perfectly.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 Say Hello to Modules — The Real MVPs
&lt;/h2&gt;

&lt;p&gt;Ad-hoc commands only work because of &lt;strong&gt;modules&lt;/strong&gt;. These are the tools Ansible uses under the hood to get things done.&lt;/p&gt;

&lt;p&gt;Think of them like little assistants — each with a specialty.&lt;/p&gt;

&lt;p&gt;Here are a few you’ll use all the time:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Module&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Docs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ping&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Tests connection + checks Python&lt;/td&gt;
&lt;td&gt;&lt;a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/ping_module.html" rel="noopener noreferrer"&gt;🔗&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;command&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Runs simple shell commands&lt;/td&gt;
&lt;td&gt;&lt;a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html" rel="noopener noreferrer"&gt;🔗&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;apt&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Installs/removes packages (Debian/Ubuntu)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html" rel="noopener noreferrer"&gt;🔗&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;service&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Starts, stops, or restarts services&lt;/td&gt;
&lt;td&gt;&lt;a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html" rel="noopener noreferrer"&gt;🔗&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Bookmark these — you’ll thank yourself later.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Let’s Run Some Ad-Hoc Commands
&lt;/h2&gt;

&lt;p&gt;Everything’s prepped. Inventory? ✅ &lt;br&gt;
Containers running? ✅&lt;br&gt;
SSH working? ✅&lt;/p&gt;

&lt;p&gt;Let’s make Ansible &lt;em&gt;do something&lt;/em&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  ✅ 1. Can We Even Talk to the Nodes?
&lt;/h3&gt;

&lt;p&gt;Before you do anything fancy with Ansible, you need to know: &lt;em&gt;Can it even reach the nodes?&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible &lt;span class="nt"&gt;-i&lt;/span&gt; inventory all &lt;span class="nt"&gt;-m&lt;/span&gt; ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Expected output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;node&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;SUCCESS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"ping"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pong"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;node&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;SUCCESS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"ping"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pong"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;node&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;SUCCESS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"ping"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pong"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What’s actually happening here?&lt;/p&gt;

&lt;p&gt;Ansible is connecting to each node over SSH using the credentials you provided. Once it connects, it runs a tiny Python script on the other side. If everything goes smoothly, you get that sweet &lt;code&gt;"pong"&lt;/code&gt; back.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;📡 It’s a &lt;em&gt;functional&lt;/em&gt; ping — not just "is the host alive?" but "can Ansible do its thing over SSH and is Python ready to go?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is your green light — your official &lt;em&gt;“we’re in business”&lt;/em&gt; signal.&lt;/p&gt;




&lt;h3&gt;
  
  
  💬 2. Run a Basic Shell Command
&lt;/h3&gt;

&lt;p&gt;Now that Ansible can reach your nodes, let’s start telling them what to do. The &lt;code&gt;command&lt;/code&gt; module is the simplest way to do that.&lt;/p&gt;

&lt;p&gt;Want to know how long each container’s been running?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible &lt;span class="nt"&gt;-i&lt;/span&gt; inventory all &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="s2"&gt;"uptime"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Need a quick view of disk usage?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible &lt;span class="nt"&gt;-i&lt;/span&gt; inventory all &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="s2"&gt;"df -h"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re not running these commands &lt;em&gt;on your machine&lt;/em&gt; — you’re telling Ansible:&lt;br&gt;&lt;br&gt;
“Go log into each container, run this command, and tell me what they say.”&lt;/p&gt;


&lt;h3&gt;
  
  
  📦 3. Installing a Package
&lt;/h3&gt;

&lt;p&gt;Let’s say you need a tool like &lt;code&gt;curl&lt;/code&gt; on all your nodes. Rather than SSHing into each one and manually installing it, you let Ansible handle it for you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible &lt;span class="nt"&gt;-i&lt;/span&gt; inventory all &lt;span class="nt"&gt;-m&lt;/span&gt; apt &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="s2"&gt;"name=curl state=present update_cache=true"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you get a permission denied error, no worries — escalate privileges with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible &lt;span class="nt"&gt;-i&lt;/span&gt; inventory all &lt;span class="nt"&gt;-m&lt;/span&gt; apt &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="s2"&gt;"name=curl state=present update_cache=true"&lt;/span&gt; &lt;span class="nt"&gt;-b&lt;/span&gt; &lt;span class="nt"&gt;-K&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What’s really cool here is that Ansible isn’t blindly running &lt;code&gt;apt install curl&lt;/code&gt;. It first checks: &lt;em&gt;Is curl already installed? Is the package cache fresh?&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Only if needed, it’ll install the package. That’s idempotence — and it’s a core part of what makes Ansible feel like automation rather than scripting.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🔐 Notice how we &lt;em&gt;only&lt;/em&gt; added sudo escalation (&lt;code&gt;-b&lt;/code&gt;) when we had to? That’s intentional. Ansible encourages a “least privilege” mindset — do what you can as a normal user, and elevate only when it’s necessary.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h3&gt;
  
  
  🧽 4. Removing a Package
&lt;/h3&gt;

&lt;p&gt;And when it’s time to clean up?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible &lt;span class="nt"&gt;-i&lt;/span&gt; inventory all &lt;span class="nt"&gt;-m&lt;/span&gt; apt &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="s2"&gt;"name=curl state=absent"&lt;/span&gt; &lt;span class="nt"&gt;-b&lt;/span&gt; &lt;span class="nt"&gt;-K&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same logic as before — Ansible checks the current state, and if the package is present, it removes it. That’s the automation magic: you describe the state you &lt;em&gt;want&lt;/em&gt;, and Ansible makes it so.&lt;/p&gt;




&lt;h2&gt;
  
  
  😌 When Should You Use Ad-Hoc Commands?
&lt;/h2&gt;

&lt;p&gt;From what I’ve gathered so far, ad-hoc commands are amazing for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quick testing&lt;/li&gt;
&lt;li&gt;Troubleshooting&lt;/li&gt;
&lt;li&gt;Exploring modules&lt;/li&gt;
&lt;li&gt;Doing “just one thing” on the fly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But if you’re doing something over and over — or want consistency across machines — you’ll want to write a &lt;strong&gt;playbook&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We’ll do that next.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Recap Time
&lt;/h2&gt;

&lt;p&gt;You’ve done a lot in a short time. Here’s what you’ve accomplished:&lt;/p&gt;

&lt;p&gt;✅ Set up a control node + managed nodes using Docker&lt;br&gt;
✅ Wrote your first inventory file&lt;br&gt;
✅ Used key Ansible modules&lt;br&gt;
✅ Ran real tasks using privilege escalation&lt;/p&gt;

&lt;p&gt;You didn’t even touch a playbook — and look how far you’ve come.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Coming Up Next…
&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;Part 3&lt;/strong&gt;, we’ll move from one-off commands to proper automation. That means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing your first playbook&lt;/li&gt;
&lt;li&gt;Getting comfy with YAML&lt;/li&gt;
&lt;li&gt;Running repeatable tasks across all your nodes&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Got questions? Stuck on something? I’m learning this stuff too, so feel free to drop a comment — I’ll either answer it or figure it out right beside you 🚀&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>devops</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Beginner’s DevOps Journey: Starting with Ansible (Part 1)</title>
      <dc:creator>Shehar Yar Khan</dc:creator>
      <pubDate>Sat, 12 Apr 2025 18:24:27 +0000</pubDate>
      <link>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-1-4ke9</link>
      <guid>https://dev.to/sheharyar566/a-beginners-devops-journey-starting-with-ansible-part-1-4ke9</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"This is the first post in my series on learning Ansible from scratch as part of my transition into DevOps. If you're looking to get hands-on with automation, you're in the right place."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧭 Why I Started Learning Ansible
&lt;/h2&gt;

&lt;p&gt;I’ve been seriously considering a career shift into DevOps.&lt;/p&gt;

&lt;p&gt;I've always been fascinated by what happens after the code is written—how it gets deployed, how environments are configured, how systems scale without burning to the ground. The more I looked into it, the more I saw one common thread: &lt;strong&gt;automation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s when I started noticing &lt;strong&gt;Ansible&lt;/strong&gt; popping up everywhere:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On job listings&lt;/li&gt;
&lt;li&gt;In blog posts&lt;/li&gt;
&lt;li&gt;In DevOps courses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I kept seeing things like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“If you're new to DevOps, start with Ansible.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I don’t know if that’s a good advice or not—but here we are. And for me, it made sense. Ansible seemed like the &lt;strong&gt;perfect entry point&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Written in &lt;strong&gt;YAML&lt;/strong&gt;, which is super readable (and I had experience with thanks to Flutter).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agentless&lt;/strong&gt;, so I didn’t have to install anything on remote machines.&lt;/li&gt;
&lt;li&gt;Great for &lt;strong&gt;automating repetitive tasks&lt;/strong&gt;, which is basically the DevOps way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I dove in. And instead of just taking notes, I decided to turn this into a &lt;strong&gt;public learning journey&lt;/strong&gt;—a series of posts that document every step of the way, with examples, breakdowns, and lessons learned.&lt;/p&gt;

&lt;p&gt;If you're also looking to get into DevOps but don't know where to start, this series might be just the thing to help you take that first step.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 How I'm Learning
&lt;/h2&gt;

&lt;p&gt;I’m learning by doing (and of-course, by going through some tutorials and documentation), in small, focused sessions.&lt;/p&gt;

&lt;p&gt;Here’s what my setup looks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;Docker-based Ansible lab&lt;/strong&gt; (I’ll walk you through this in the next post)&lt;/li&gt;
&lt;li&gt;Short, real-world examples (like installing packages, managing users, etc.)&lt;/li&gt;
&lt;li&gt;A “try it, break it, fix it” mindset&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s hands-on, beginner-friendly, and focused on &lt;strong&gt;real progress&lt;/strong&gt; over perfect understanding.&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 What This Series Covers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Title&lt;/th&gt;
&lt;th&gt;What You'll Learn&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Why I Started Learning Ansible&lt;/td&gt;
&lt;td&gt;You are here!&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Setting Up an Ansible Lab with Docker&lt;/td&gt;
&lt;td&gt;Get a working lab in 5 minutes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Understanding Inventories &amp;amp; Hosts&lt;/td&gt;
&lt;td&gt;Targeting machines with Ansible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Writing Your First Playbook&lt;/td&gt;
&lt;td&gt;Automating tasks, one YAML at a time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Getting Modular with Roles&lt;/td&gt;
&lt;td&gt;Reusing and organizing your playbooks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Using Variables, Loops &amp;amp; Conditionals&lt;/td&gt;
&lt;td&gt;Making automation flexible and smart&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Common Errors &amp;amp; How to Fix Them&lt;/td&gt;
&lt;td&gt;Debugging and staying sane&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;A Small Project to Wrap It Up&lt;/td&gt;
&lt;td&gt;Apply everything in a real use case&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧰 What You'll Need to Follow Along
&lt;/h2&gt;

&lt;p&gt;Not much! Just:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A system with &lt;strong&gt;Docker installed&lt;/strong&gt; (Mac, Windows, or Linux is fine)&lt;/li&gt;
&lt;li&gt;Basic command line knowledge&lt;/li&gt;
&lt;li&gt;Curiosity and patience (especially when YAML complains about indentation 😅)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔜 What's Next?
&lt;/h2&gt;

&lt;p&gt;In the next post, we’ll build a quick Ansible playground using Docker—no servers, no cloud accounts, no stress.&lt;/p&gt;

&lt;p&gt;➡️ &lt;strong&gt;Part 2 is coming in a few days—follow me here on dev.to so you don't miss it!&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Got questions? Drop them in the comments. And if you're also starting out with Ansible, let me know—I'd love to hear how your journey's going too!&lt;/p&gt;

</description>
      <category>ansible</category>
      <category>devops</category>
      <category>automation</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🧪 Build a Local Ansible Lab with Docker (No VMs Needed)</title>
      <dc:creator>Shehar Yar Khan</dc:creator>
      <pubDate>Wed, 09 Apr 2025 15:58:16 +0000</pubDate>
      <link>https://dev.to/sheharyar566/build-a-local-ansible-lab-with-docker-no-vms-needed-1gf6</link>
      <guid>https://dev.to/sheharyar566/build-a-local-ansible-lab-with-docker-no-vms-needed-1gf6</guid>
      <description>&lt;p&gt;I recently put together a lightweight Ansible lab using Docker — and it’s been a super clean way to test playbooks without spinning up virtual machines or using the cloud.&lt;/p&gt;

&lt;p&gt;Whether you're learning Ansible or just want a disposable playground, this setup gives you:&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚙️ What's Inside?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🐧 &lt;strong&gt;Three Ubuntu containers&lt;/strong&gt; (managed nodes)&lt;/li&gt;
&lt;li&gt;🔐 SSH enabled (user: &lt;code&gt;root&lt;/code&gt;, password: &lt;code&gt;root&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;🐍 Python pre-installed for Ansible modules&lt;/li&gt;
&lt;li&gt;🌐 Docker network named &lt;code&gt;ansible&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;🎯 Port forwarding so you can SSH from your local machine&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🚀 Why I Built This
&lt;/h3&gt;

&lt;p&gt;I wanted a quick, minimal lab that would let me focus on learning &lt;strong&gt;Ansible&lt;/strong&gt; without spending time managing VMs or cloud resources. With Docker Compose, I just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up &lt;span class="nt"&gt;--build&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…and I’m ready to automate.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧪 Try It Out
&lt;/h3&gt;

&lt;p&gt;Here’s what you need to do:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repo
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   git clone https://github.com/sheharyar566/ansible-docker-lab.git
   &lt;span class="nb"&gt;cd &lt;/span&gt;ansible-docker-lab
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Start the lab
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker-compose up &lt;span class="nt"&gt;--build&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;SSH into a node
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ssh root@localhost &lt;span class="nt"&gt;-p&lt;/span&gt; 2221
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create an inventory file for Ansible and run:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   ansible &lt;span class="nt"&gt;-i&lt;/span&gt; inventory.ini all &lt;span class="nt"&gt;-m&lt;/span&gt; ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔗 Repo
&lt;/h3&gt;

&lt;p&gt;👉 &lt;a href="https://github.com/sheharyar566/ansible-docker-lab" rel="noopener noreferrer"&gt;GitHub – Ansible Docker Lab&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🌟 Found This Useful?
&lt;/h3&gt;

&lt;p&gt;If this lab helped you out or saved you time, feel free to give the repo a star on GitHub! It’s a great way to show your support and help others find it too.&lt;/p&gt;

&lt;p&gt;Happy automating! ⚙️&lt;/p&gt;

</description>
      <category>devops</category>
      <category>docker</category>
      <category>ansible</category>
    </item>
  </channel>
</rss>
