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

Categories

Ansible Automation: Getting Started Guide for Linux Administrators (2026)

Ansible Automation: Getting Started Guide for Linux Administrators (2026)

Quick Summary: Ansible is an open-source automation tool that lets you configure servers, deploy applications, and orchestrate complex workflows from a single control machine β€” without installing agents on managed servers. It uses SSH for communication and YAML for configuration, making it the most approachable automation tool for Linux administrators in 2026.

Ansible automation configuring multiple servers

What Is Ansible?

Ansible is an agentless automation platform created by Michael DeHaan and acquired by Red Hat in 2015. Unlike tools like Puppet or Chef that require agent software on every managed server, Ansible connects via standard SSH and executes tasks remotely. This agentless architecture means you can start automating within minutes β€” if you can SSH to a server, you can automate it with Ansible.

Ansible uses YAML (Yet Another Markup Language) for its configuration files called playbooks, making them human-readable even for people who have never used automation tools before.

Why Choose Ansible?

FeatureAnsiblePuppetChef
Agent requiredNo (agentless, SSH)Yes (puppet-agent)Yes (chef-client)
LanguageYAML (declarative)Puppet DSLRuby DSL
Learning curveLowMediumHigh
ArchitecturePush-basedPull-basedPull-based
IdempotentYesYesYes
CommunityVery largeLargeMedium

Installing Ansible

Ansible runs on the control node (your workstation or a management server). Managed servers need only SSH access and Python.

  1. Debian/Ubuntu: sudo apt install ansible
  2. RHEL/AlmaLinux/Rocky: sudo dnf install ansible-core
  3. Via pip (any system): pip3 install ansible
  4. Verify: ansible --version

Key Concepts

ConceptDescription
Control NodeMachine where Ansible runs (your workstation)
Managed NodesServers being configured (require SSH + Python)
InventoryFile listing managed servers and groups
PlaybookYAML file defining automation tasks
TaskSingle action (install package, copy file, etc.)
ModuleBuilt-in function for specific operations
RoleReusable collection of tasks, files, and variables
HandlerTask triggered by changes (e.g., restart service after config change)

Creating Your First Inventory

The inventory file defines which servers Ansible manages. Create /etc/ansible/hosts or a project-specific inventory file:

  • Define server groups with meaningful names: [webservers], [databases], [monitoring]
  • List servers by hostname or IP under each group
  • Set variables per host or per group (SSH user, port, Python path)
  • Use [all:vars] for variables that apply to every server

Testing Connectivity

After creating your inventory, test that Ansible can connect to all servers:

  • ansible all -m ping β€” Ping all servers in inventory
  • ansible webservers -m ping β€” Ping only the webservers group

Writing Your First Playbook

Playbooks are YAML files that describe automation tasks. A basic playbook structure includes:

  1. Target hosts β€” Which servers to configure
  2. Become (sudo) β€” Whether to run tasks with elevated privileges
  3. Tasks β€” Ordered list of actions to perform

Common Modules for Server Administration

ModulePurposeExample Use
apt / dnfPackage managementInstall nginx, update all packages
copyCopy files to remoteDeploy configuration files
templateDeploy Jinja2 templatesDynamic config with variables
serviceManage system servicesStart, stop, restart, enable
userManage user accountsCreate users, set SSH keys
fileManage files and directoriesSet permissions, create dirs
firewalld / ufwManage firewall rulesOpen ports, allow services
cronManage cron jobsSchedule automated tasks
command / shellRun arbitrary commandsCustom scripts (use sparingly)

Practical Playbook Examples

1. Secure Server Initial Setup

A playbook that performs initial server hardening:

  • Update all packages to latest versions
  • Install essential security tools (fail2ban, unattended-upgrades)
  • Configure SSH with hardened settings
  • Set up firewall rules
  • Create admin user with SSH key

2. Web Server Deployment

A playbook that sets up a web server:

  • Install web server package (NGINX or Apache)
  • Deploy virtual host configuration from template
  • Copy website files to document root
  • Enable and start the service
  • Open firewall ports 80 and 443

Variables and Templates

Variables make playbooks reusable across different environments:

  • Inventory variables β€” Set per host or group in inventory file
  • Playbook variables β€” Defined in the playbook vars: section
  • External variable files β€” Loaded with vars_files:
  • Ansible Vault β€” Encrypt sensitive variables (passwords, API keys): ansible-vault encrypt vars/secrets.yml

Roles: Reusable Automation

Roles organize complex automation into reusable components. A role bundles tasks, handlers, templates, files, and variables into a standard directory structure:

  • tasks/main.yml β€” The main list of tasks
  • handlers/main.yml β€” Handlers triggered by tasks
  • templates/ β€” Jinja2 template files
  • files/ β€” Static files to copy
  • vars/main.yml β€” Role variables
  • defaults/main.yml β€” Default variable values

Ansible Galaxy provides thousands of community roles: ansible-galaxy install geerlingguy.nginx

Ansible Best Practices

  • Use roles for anything reusable across projects
  • Use Ansible Vault for all sensitive data β€” never store passwords in plain text
  • Test in staging before running on production β€” use --check for dry runs
  • Use tags to selectively run parts of playbooks: ansible-playbook site.yml --tags "nginx"
  • Keep inventory organized by environment: inventories/production/, inventories/staging/
  • Version control your playbooks β€” treat infrastructure as code
  • Use handlers to restart services only when configuration actually changes

Frequently Asked Questions

Does Ansible require agent software on managed servers?

No. Ansible is agentless β€” it connects via SSH and requires only Python on the managed server. Most Linux distributions include Python by default, so Ansible works immediately without installing anything on managed servers.

What is the difference between Ansible and Terraform?

Ansible is a configuration management tool β€” it configures and manages existing servers (install packages, deploy apps, set up services). Terraform is an infrastructure provisioning tool β€” it creates and destroys cloud resources (VMs, networks, storage). Many teams use both: Terraform to create infrastructure, then Ansible to configure it.

How do I handle sensitive data like passwords?

Use Ansible Vault to encrypt sensitive variable files: ansible-vault encrypt secrets.yml. Run playbooks with --ask-vault-pass or --vault-password-file. Never commit unencrypted passwords to version control.

Can Ansible manage Windows servers?

Yes. Ansible manages Windows servers via WinRM (Windows Remote Management) instead of SSH. Windows modules include win_package, win_service, win_copy, and more. The control node must still be Linux or macOS.

Related Resources

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.