Initial Setup

Get Ansible installed and execute your first playbook. This guide walks you through installation and running your first automation.

🎯 What You’ll Accomplish

By the end of this tutorial, you’ll have:

  • βœ… Ansible installed and verified
  • βœ… Your first playbook created
  • βœ… First automation executed

πŸ“‹ Prerequisites

  • Linux or macOS (or WSL2 on Windows)
  • Python 3.8 or later
  • SSH access to target machines (or localhost for testing)

πŸ’Ύ Step 1: Install Ansible

Using pip (Recommended)

python3 -m pip install --user ansible

macOS (Homebrew)

brew install ansible

Ubuntu/Debian

sudo apt update
sudo apt install ansible

Verify Installation

ansible --version

πŸš€ Step 2: Create Your First Playbook

Create hello.yml:

---
- name: My First Playbook
  hosts: localhost
  connection: local
  tasks:
    - name: Print hello message
      ansible.builtin.debug:
        msg: "Hello, Ansible!"

    - name: Create a file
      ansible.builtin.file:
        path: /tmp/ansible-test.txt
        state: touch

    - name: Write to file
      ansible.builtin.copy:
        content: "Ansible was here!"
        dest: /tmp/ansible-test.txt

▢️ Step 3: Run Your Playbook

ansible-playbook hello.yml

Expected output shows tasks being executed and their status (ok, changed, failed).

βœ… Verification Checklist

Before moving forward, verify:

  • ansible --version shows Ansible installed
  • Playbook executes without errors
  • File created at /tmp/ansible-test.txt

πŸŽ‰ You’re Done!

You’ve successfully installed Ansible and run your first playbook. You’re ready for more advanced automation.

πŸ“š What’s Next?

Quick learner: Ansible Quick Start

Code-first learner: Ansible By Example

Last updated