Automating Linux Server Configuration with Ansible

Ansible automates server configuration using plain YAML playbooks and SSH — no agent software required on managed hosts, which makes it genuinely easy to adopt incrementally on existing infrastructure.

---
- name: Configure web servers
  hosts: webservers
  become: true
  tasks:
    - name: Install nginx
      apt:
        name: nginx
        state: present
        update_cache: true

    - name: Ensure nginx is running
      service:
        name: nginx
        state: started
        enabled: true

    - name: Deploy site configuration
      template:
        src: site.conf.j2
        dest: /etc/nginx/sites-available/mysite.conf
      notify: reload nginx

  handlers:
    - name: reload nginx
      service:
        name: nginx
        state: reloaded
ansible-playbook -i inventory.ini playbook.yml

Idempotency: The Core Concept

Ansible tasks are designed to be idempotent — running the same playbook twice produces the same end state without duplicating work or causing errors, since each module checks current state before making a change. This is what lets you safely re-run a playbook against a server repeatedly, treating your infrastructure configuration as reproducible code rather than a one-time manual setup script.