This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Ansible Beginner's Quickstart Guide Cheat Sheet

A step-by-step beginner's guide to Ansible: installation, project structure, inventory configuration, writing playbooks, and executing automation runs.

· Published

A hands-on, zero-to-one guide to installing Ansible, organizing inventory files, authoring your first YAML playbook, and orchestrating server tasks.

🔗 Related: Ansible Core Cheat Sheet · Ansible Roles Cheat Sheet · Ansible Playbook Examples

Installation

# macOS (Homebrew)
brew install ansible

# Ubuntu / Debian
sudo apt update && sudo apt install -y ansible

# Python Pip (Universal)
pip install ansible

See: Official Ansible Installation Docs


Project Setup

mkdir -p ~/ansible-setup
cd ~/ansible-setup

Create a dedicated working directory for your inventory, playbooks, and variable definitions.


Configuration Files

Inventory File

hosts

[webservers]
192.168.0.10
192.168.0.11

[databases]
192.168.0.20

[local]
localhost ansible_connection=local

Inventories define target nodes grouped logically. You can target localhost using ansible_connection=local to test automation locally without SSH.

See: Ansible How to build your inventory


Playbook Definition

playbook.yml

---
- name: Basic Server Provisioning
  hosts: webservers
  become: true
  tasks:
    - name: Update apt package cache
      apt:
        update_cache: yes
        cache_valid_time: 3600

    - name: Ensure Nginx is installed
      apt:
        name: nginx
        state: present

    - name: Start Nginx and enable on boot
      service:
        name: nginx
        state: started
        enabled: yes

    - name: Create hello world banner
      shell: echo "Managed by Ansible" > /tmp/motd.txt

Execution

Validating & Running

Verify connectivity via ad-hoc ping:

ansible -i hosts all -m ping

Run the complete playbook against your inventory:

ansible-playbook -i hosts playbook.yml

Dry Run (Check Mode)

Preview potential changes without applying them to remote nodes:

ansible-playbook -i hosts playbook.yml --check --diff

References

Related topics