No history yet

Introduction to Ansible

What Is Ansible?

Managing one computer is simple. Managing five is a little harder. Now, imagine you're in charge of hundreds or even thousands of servers. Updating software, deploying applications, and ensuring every machine has the correct configuration becomes a monumental task. Doing this manually is slow, repetitive, and prone to human error.

Ansible is an open-source automation tool used for configuration management, application deployment, and task automation.

Think of Ansible as a master conductor for your entire IT orchestra. Instead of giving instructions to each musician (or server) one by one, you give a single set of instructions to the conductor. The conductor then ensures every musician plays their part perfectly and in sync. This is what Ansible does for your servers, a process often called IT orchestration.

How Ansible Works

Ansible's design is based on two types of computers: a control node and managed nodes. The control node is the computer you run Ansible from. The managed nodes are the servers you want to manage. A single control node can manage many managed nodes.

What makes Ansible special is its agentless architecture. Many automation tools require you to install special software, called an agent, on every single server you want to manage. These agents constantly run in the background, checking in with a central master server.

Ansible doesn't do this. It communicates with your managed nodes using SSH (Secure Shell), a standard and secure way to connect to remote servers. Since virtually all Linux and macOS servers already have an SSH server running, there's nothing extra to install on them. This simplicity is a core reason for Ansible's popularity.

The Language of Playbooks

So how do you tell Ansible what to do? You write a set of instructions called a playbook.

Ansible playbooks are the cornerstone of Ansible automation.

Playbooks are written in a simple data format called YAML (which stands for "YAML Ain't Markup Language"). YAML is designed to be easy for humans to read and write. It uses indentation (spaces) to organize information, rather than brackets or tags. This makes the files clean and uncluttered.

Here's what a very basic playbook looks like. This example targets a group of servers defined as webservers and uses the apt package manager to make sure the latest version of the Apache web server is installed.

---
- name: Configure web servers
  hosts: webservers
  become: yes
  tasks:
    - name: Ensure apache is at the latest version
      apt:
        name: apache2
        state: latest

Even without knowing Ansible, you can probably guess what this does. The name fields describe the purpose of the playbook and the task. The hosts line specifies which servers to run it on. The tasks section lists the actions to perform.

Setting Up Your Environment

Ready to get started? First, you'll need to install Ansible on your control node. Ansible is written in Python, so it runs on Linux, macOS, or any machine with Python installed. The most common way to install it on a Debian-based system like Ubuntu is with these commands:

# Update your package index
sudo apt update

# Install the software-properties-common package
sudo apt install software-properties-common

# Add the official Ansible PPA (Personal Package Archive)
sudo add-apt-repository --yes --update ppa:ansible/ansible

# Install Ansible
sudo apt install ansible

Once Ansible is installed on your control node, you just need to ensure your managed nodes are ready. There isn't much to do.

  1. SSH Access: Your control node must be able to connect to the managed nodes via SSH. Typically, this is done by copying your SSH public key to the managed nodes, allowing for passwordless login.
  2. Python: Ansible requires Python to be installed on the managed nodes to execute its commands. Most modern Linux distributions come with Python 3 installed by default, so you're usually covered.

And that's it. With SSH access and Python in place, your managed nodes are ready to be automated by Ansible.

Quiz Questions 1/5

What is the primary role of Ansible in an IT environment?

Quiz Questions 2/5

What does it mean for Ansible to have an "agentless" architecture?