Ansible Automation

Introduction to Ansible

Lesson 1 of 12 · 6 min · Beginner

Ansible is an open-source, agentless automation tool by Red Hat. It uses simple, human-readable YAML files called playbooks to automate configuration management, application deployment, and orchestration across your entire fleet.

Key Characteristics

Ansible is designed to be minimal in nature, consistent, and highly reliable. Here is what makes it stand out from legacy configuration tools.

Agentless

No agents are required on managed nodes. It natively uses SSH for Linux/UNIX systems and WinRM for Windows.

Declarative Playbooks

You describe the desired state in YAML; Ansible figures out the exact commands and steps needed to get the system there.

Idempotent Modules

Tasks are safe to run multiple times. If a system is already in the desired state, Ansible recognizes this and does absolutely nothing.

Extensible

Custom modules, plugins, and roles allow you to flexibly extend Ansible to orchestrate complex workflows, cloud providers, and networking devices.

How Ansible Works

Ansible operates on a simple push-based architecture from a central control node out to your infrastructure.

Core Components

  • Control Node The machine where you run ansible or ansible-playbook (requires Linux/macOS with Python).
  • Managed Nodes The target servers, network devices, or virtual machines being automated.
  • Inventory A list (INI or YAML format) defining your managed hosts and organizing them into groups.
  • Modules Reusable units of code that execute tasks (e.g., package, file, service).
  • Playbooks An ordered list of plays (which map target hosts to specific tasks).

Modules & Quick Commands

Common Module Categories

  • System user, group, package, service
  • File copy, template, file
  • Command command, shell
  • Networking nxos, ios, eos, junos
  • Cloud / App aws, azure, gcp, docker, kubernetes

terminal

# Check host connectivity using the ping module
$ ansible all -m ping -i inventory

# Run an ad-hoc command on all hosts
$ ansible all -a "uptime" -i inventory

# Execute a declarative playbook
$ ansible-playbook -i inventory site.yml
$

Automation Types: Push vs Pull

Configuration management tools generally fall into two architectural paradigms. Ansible uses the Push model, which is why it doesn't require agents.

FeaturePush Architecture Pull Architecture
MechanismControl node sends instructions directly to the servers.Servers continuously fetch configs from a central master server.
Agent RequirementNo agents needed (Agentless).Requires a background agent running on every host.
SpeedImmediate execution when triggered.Execution depends on the agent's polling interval.
Tool ExamplesAnsible, TerraformPuppet, Chef