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 ansiblemacOS (Homebrew)
brew install ansibleUbuntu/Debian
sudo apt update
sudo apt install ansibleVerify 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.ymlExpected output shows tasks being executed and their status (ok, changed, failed).
β Verification Checklist
Before moving forward, verify:
-
ansible --versionshows 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