Table of Contents
ToggleIntroduction.
Getting started with Ansible playbooks can feel both exciting and intimidating, especially when you first step into the world of automation and realize just how much power a few lines of YAML can hold. For many beginners, the concept of declaring a desired system state instead of writing lengthy procedural scripts feels almost magical, and that’s exactly where Ansible shines: it makes automation simple, predictable, and repeatable without requiring agents, complex orchestration tools, or steep learning curves. Whether you’re a sysadmin automating repetitive tasks, a DevOps engineer streamlining deployments, or a curious learner exploring infrastructure as code for the first time, Ansible gives you a clean, human-readable way to define what your servers should look like and how they should behave. But before you start building larger roles, managing fleets of machines, or handling cloud environments, it helps to begin with the fundamentals the first essential tasks that every Ansible user should know, practice, and understand.
These building blocks form the core of almost everything you will do later: connecting to servers, installing packages, managing users, deploying configuration files, starting services, creating directories, and handling templates. Mastering these basics early on not only improves your confidence but also ensures that you write efficient playbooks that behave consistently, remain idempotent, and scale easily as your environment grows.
In this guide, we’ll walk through your first ten Ansible tasks simple, practical, and immediately useful steps that mirror real-world operations you’ll perform on almost any Linux server. By exploring how each task works and seeing how they fit together inside a playbook, you’ll gain a clear understanding of Ansible’s workflow and how it transforms manual steps into fully automated actions.
Every example is designed with beginners in mind, focusing on clarity, readability, and why each task matters. By the time you finish this introduction and move through the upcoming tasks, you’ll be ready to confidently use Ansible not just as a tool, but as a core part of your automation toolkit, capable of saving you time, eliminating errors, and helping you manage systems with precision and ease.
What You Need Before You Start
- A control machine (Linux/macOS/WSL recommended)
- At least one remote Linux host (or a local VM)
- SSH access to the host
- Ansible installed:


Your project structure might look like:
my-first-playbook/
└── site.yml
Your First 10 Ansible Tasks
Below is a complete beginner-friendly example. Each task is explained and combined into one playbook.
1. Ping the Server
Confirm Ansible can connect.
– name: Test connectivity hosts: all tasks: – name: Ping the target host ansible.builtin.ping:2. Update the Package Cache
– name: Update apt cache ansible.builtin.apt: update_cache: yes when: ansible_os_family == “Debian”3. Install Essential Packages
– name: Install utilities ansible.builtin.package: name: – git – curl – htop state: present4. Create a User
– name: Create a new user ansible.builtin.user: name: devuser shell: /bin/bash state: present5. Add an SSH Key for the User
– name: Add SSH key for devuser ansible.builtin.authorized_key: user: devuser key: “{{ lookup(‘file’, ‘~/.ssh/id_rsa.pub’) }}”6. Copy a Configuration File
– name: Copy custom config ansible.builtin.copy: src: files/custom.conf dest: /etc/custom.conf mode: ‘0644’7. Manage a Service
– name: Ensure NGINX is running ansible.builtin.service: name: nginx state: started enabled: true8. Create a Directory
– name: Create logs directory ansible.builtin.file: path: /var/log/myapp state: directory mode: ‘0755’9. Deploy a Simple Template
Templates let you add variables:
templates/index.html.j2:
Hello from {{ ansible_hostname }}!
Task:
– name: Deploy HTML template ansible.builtin.template: src: templates/index.html.j2 dest: /usr/share/nginx/html/index.html10. Reboot the Server (Only If Needed)
– name: Reboot if kernel updated ansible.builtin.reboot: msg: “Reboot triggered by Ansible” when: ansible_facts.packages[‘linux-image-*’] is definedFull Example: Your First Complete Playbook
Save this as site.yml:
– name: My First Ansible Playbook hosts: all become: yes tasks: – name: Ping the host ansible.builtin.ping: – name: Update apt cache ansible.builtin.apt: update_cache: yes when: ansible_os_family == “Debian” – name: Install utilities ansible.builtin.package: name: – git – htop – curl state: present – name: Create user ansible.builtin.user: name: devuser shell: /bin/bash – name: Add SSH key for devuser ansible.builtin.authorized_key: user: devuser key: “{{ lookup(‘file’, ‘~/.ssh/id_rsa.pub’) }}” – name: Copy custom config ansible.builtin.copy: src: files/custom.conf dest: /etc/custom.conf mode: ‘0644’ – name: Install and start nginx ansible.builtin.package: name: nginx state: present – name: Ensure nginx running ansible.builtin.service: name: nginx state: started enabled: true – name: Create application log directory ansible.builtin.file: path: /var/log/myapp state: directory mode: ‘0755’ – name: Deploy HTML template ansible.builtin.template: src: templates/index.html.j2 dest: /usr/share/nginx/html/index.htmlRun it:
ansible-playbook site.yml
What You Just Accomplished
With one playbook, you:
- Verified server connectivity
- Installed packages
- Created a user and SSH key
- Managed files, directories, and templates
- Installed and started a service
- Configured a simple web page
These are the building blocks you’ll use in every automation project.
Next Steps
If you want to go further, here are some great follow-ups:
- Convert this into a role
- Add handlers for smarter restarts
- Use variables and group_vars
- Use Ansible Vault for secrets
- Set up a CI pipeline with ansible-lint + Molecule
Conclusion.
Getting started with Ansible playbooks doesn’t have to be overwhelming. By walking through your first ten essential tasks, you’ve already covered the core fundamentals that power most real-world automation: connecting to hosts, installing software, managing users, deploying files, configuring services, and using templates. These tasks form the backbone of everyday infrastructure work, and now that you understand how they fit together inside a playbook, you’re well on your way to building more advanced automation workflows.
As you continue exploring Ansible, you’ll discover even more powerful features roles, variables, handlers, inventories, collections, and CI pipelines that can transform simple playbooks into scalable automation frameworks. But the most important step is the one you’ve already taken: starting with the basics and learning by doing. With these foundational concepts under your belt, you’re ready to expand your skills, automate larger environments, and bring consistency and reliability to every system you manage. Keep experimenting, keep refining, and soon Ansible will feel like one of the most natural tools in your DevOps toolkit.
- For more information about Ansible, you can refer to Jeevi’s page.



