🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now β†’
Menu

Categories

Ansible Playbooks for Beginners: Automate Your First Server Setup

Ansible Playbooks for Beginners: Automate Your First Server Setup

Ansible is the most popular agentless automation tool for IT infrastructure. It works over SSH, requiring no software on target servers.

Installing Ansible

sudo apt update && sudo apt install -y ansible
sudo dnf install -y ansible-core
ansible --version

Inventory Setup

[webservers]
web1 ansible_host=192.168.1.10
web2 ansible_host=192.168.1.11

[all:vars]
ansible_user=deploy

Your First Playbook

---
- name: Configure web servers
  hosts: webservers
  become: yes
  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present
    - name: Start Nginx
      systemd:
        name: nginx
        state: started
        enabled: yes

Running Playbooks

ansible-playbook setup.yml --syntax-check
ansible-playbook setup.yml --check
ansible-playbook setup.yml

Using Roles

ansible-galaxy init roles/webserver

Master Ansible with our DevOps eBook collection.

Share this article:
Dargslan Editorial Team (Dargslan)
About the Author

Dargslan Editorial Team (Dargslan)

Collective of Software Developers, System Administrators, DevOps Engineers, and IT Authors

Dargslan is an independent technology publishing collective formed by experienced software developers, system administrators, and IT specialists.

The Dargslan editorial team works collaboratively to create practical, hands-on technology books focused on real-world use cases. Each publication is developed, reviewed, and...

Programming Languages Linux Administration Web Development Cybersecurity Networking

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.