Ansible basics

28 May, 2026

Dirk Wening
Dirk Wening
Technical Writer

Dirk arbeitet seit Januar 2025 bei NETWAYS als Junior Consultant im Zuge seiner Umschulung zum Fachinformatiker für Systemintegration. Aktuell arbeitet er in der Abteilung  NETWAYS Professional Services und strebt nach seiner Umschulung eine Übernahme zum Consulting-Team an. In seiner Freizeit unternimmt er sehr viel mit seiner Tochter oder spielt American Football.

by | May 28, 2026

Last updated: 28.05.2026

Imagine you have to install the same packages, start services and adjust configurations on 10 servers. Manually via SSH, with copy-paste commands and countless error searches.

Ansible, an open source tool developed primarily by Red Hat, automates precisely these recurring tasks. It works without agents on Linux and Windows systems, uses simple, understandable languages such as YAML or JSON and enables scalable and error-free IT processes.

This article shows you the Ansible basics step by step. Specifically, this means how to install Ansible, create your first inventory and write a simple playbook – for example, to deploy a web server on multiple machines. At the end, you will be able to get started on your own without any prior knowledge of complex programming.

Ansible basics

Ansible is based on a few building blocks that you combine to build automations. Here are the most important terms and Ansible basics with examples.

The inventory is a central file in which you manage all your hosts and host groups. You can either maintain a simple list of all servers or structure them in groups, for example by environment (dev, test, prod) or geographical location.

vim inventory.ini
---
[webserver]
web1 ansibl_host=192.168.1.10
web2 ansibl_host=192.168.1.20

[datenbank]
db1 ansible_host=192.168.1.101
db2 ansible_host=192.168.1.102

This way you could later say that a play should only be executed on the web server group.

Modules are the building blocks with which Ansible performs specific tasks. For example, they take care of installing packages (apt), copying files (copy) or managing services (service). You do not have to write your own program, but simply call up the appropriate module with the correct parameters.

-name: nginx installieren
 ansible.builtin.apt
 name: nginx
 state present

Ansible creates a web server here.

A task is a single action that Ansible executes on a host. Each task uses exactly one module and describes what should happen. You also enter a name so that you can immediately recognize which step is currently running in the output.

- name: "Paketlisten aktualisieren"
  ansible.builtin.apt:
    update_cache: true

A play is the combination of tasks and host groups. Several tasks can be used in one play. These are executed one after the other on the selected hosts. In the following, I will show you what such a play could look like.

Two tasks are executed: one installs the web server, the other starts it.

-name: "webserver installieren"
 hosts: webserver
 become: true
 tasks:
  - name: nginx installieren
    ansible.builtin.apt:
      name: nginx
      state: present

  - name: Dienst starten
    ansible.builtin.service:
      name: nginx
      state: started
      enabled: true

A playbook is the overall script. It can contain one or more plays. You start it with ansible-playbook your_playbook_name.yml.

It then executes the defined plays and tasks one after the other.

What do you need?

For the Control Node:

  • Operating system: Linux, macOS or Windows
  • Internet access
  • Python 3
  • A text editor (Vim, VS Code, Nano, etc.)

For the Test Managed Node:

  • Operating system: Linux, macOS or WIndows
  • SSH access with Sudo rights

Step 1: Install Ansible

sudo apt update
sudo apt install ansible

Step 2: Create initial inventory

In the following step you create the inventory.ini file

You then fill this in with your host details.

vim inventory.ini
[host]
host1 ansible_host=192.168.1.10

Step 3: Prepare SSH connection

After creating the inventory.ini , set up passwordless SSH access on each machine. To do this, you generate a key pair on your control node and copy the public key to each managed node.

ssh-keygen -t ed25519 -C "ansible"
ssh-copy-id user@deine.verwendete.ip

Step 4: Create a playbook

Now create your first playbook. To do this, create a YAML file in the same directory as your inventory.ini and name it webserver.yml. This play installs a web server on your host1 and starts it immediately.

vim webserver.yml

---
-name: Nginx Webserver bereitstellen
 hosts: webserver
 become: true
 tasks:
- name: Paketlisten aktualisieren
   ansible.builtin.apt:
   update_cache: yes

- name: Nginx installieren
 ansible.builtin.apt:
 name: nginx
 state: present

- name: Nginx starten
 ansible.builtin.service:
 name: nginx
 state: started
 enabled: yes
---

After saving the YAML file, you can now proceed to execute your playbook. Use the following command for this:

ansible-playbook -i inventory.ini webserver.yml --ask-bekome-pass

The command means the following:

  • We use an ansible playbook and use the inventory.ini to determine which host is affected.
  • We use the play webserver.yml and with ask-become-pass Ansible asks us for the Sudo password.

As a cross-check, you can now log in to your Manage Node and test the status of nginx .

This brings us to the end of this article on Ansible basics. I hope I was able to help you with your first steps in automation with Ansible and show you how easy it is to automate recurring tasks. Thank you for reading and good luck trying it out!

Questions or support needed?
Would you like to use Ansible productively or need help automating your infrastructure? We are happy to support you – from the initial setup to scalable operation.
Just send us a message or get in touch via our contact form and we’ll see together how we can best help you.

How did you like our article?