Agentic AI with Java: Live Cohort
Ansible

Introduction

What Ansible is, why configuration management exists, the core vocabulary from inventory to handlers, and how Ansible fits with Terraform, Docker and Jenkins.

A server is only as useful as the software and settings on it. The hard part has never been installing Java once. It is installing the same version, with the same settings, on every server, every time, and still knowing six months later exactly how each machine was built.

Ansible answers that with a simple idea: describe the state you want in a text file, and let a tool make every server match it. That file can be reviewed, versioned in Git and re-run safely, which is something no admin's memory can offer.

What Ansible is

Ansible is an open source automation tool for configuration management, application deployment and orchestration. It is sponsored by Red Hat, written in Python, and driven by YAML files called playbooks.

Three properties make it popular:

PropertyWhat it means for you
AgentlessNothing to install on the servers. Ansible connects over SSH and needs only Python on the other side
ReadablePlaybooks are YAML. Someone who has never used Ansible can still read what a playbook does
IdempotentMost modules check before they act, so running a playbook again changes only what is different

Core vocabulary

TermMeaning
Control nodeThe machine with Ansible installed, where you run ansible and ansible-playbook
Managed nodeA server that Ansible configures. It does not need Ansible installed
InventoryThe list of managed nodes, organised into groups such as webservers and dbservers
ModuleA small program that does one job: ansible.builtin.copy, ansible.builtin.dnf, ansible.builtin.service
TaskOne call to a module with its arguments, plus a name
PlayA set of tasks mapped to a set of hosts
PlaybookA YAML file with one or more plays
Ad hoc commandA single module run from the command line, without a playbook
FactsInformation Ansible gathers about each host (OS, IPs, memory) before running tasks
VariableA named value used in tasks, set in the playbook, inventory or on the command line
VaultAnsible's tool for encrypting files and values that hold secrets
HandlerA task that runs only when another task notifies it of a change
TagA label on a task, used to run or skip it from the command line
CollectionA package of modules and plugins. The built-in ones live in ansible.builtin

How a run works

Ansible push model: the control node connects over SSH, copies a module, runs it with Python, receives JSON and cleans up

When you run a playbook, Ansible reads the inventory to find the hosts, connects to each one over SSH, copies the module for the current task, runs it with the host's Python, collects the JSON result (ok, changed or failed) and moves on. It works on several hosts in parallel, so ten servers take about as long as one.

Where Ansible fits

DevOps toolchain: Git stores code, Terraform provisions servers, Ansible configures them, the application runs on top, Jenkins automates the steps

Ansible usually sits between infrastructure and application:

ToolJobRelation to Ansible
TerraformProvisioning: creates EC2 instances, VPCs, security groupsCreates the machines that Ansible then configures
AnsibleConfiguration: packages, files, users, servicesThe subject of this course
DockerPackages the application with its runtimeAnsible can install Docker and start containers on servers
KubernetesRuns containers at scaleConfigures itself declaratively, so Ansible is used less inside the cluster
JenkinsCI/CD pipelinesCan run ansible-playbook as a pipeline stage after a build

Ansible can also create cloud resources, and Terraform can run scripts on servers. In practice, most teams let each tool do what it does best: Terraform for infrastructure, Ansible for what goes on it.

What this course builds

Everything happens on one small lab on AWS: a control node and two managed nodes, one in the webservers group and one in the dbservers group. On that lab you write the playbooks a DevOps engineer writes in the first weeks of a job: creating files, installing Git, Java and Maven, deploying a website with Apache httpd, then improving those playbooks with variables, encrypted secrets, handlers and tags.

Versions used in this course

The lecture installs Ansible with pip on Amazon Linux 2023, which gives ansible 8.7 with ansible-core 2.15 (the newest release that supports the system's Python 3.9). The current release at the time of writing is ansible-core 2.21, which needs Python 3.12 or newer on the control node. Every playbook in this course works on both. Where newer versions behave differently, the lesson says so.

Start with Ansible Introduction.

Official references


Written By: Shramik Masti

How is this guide?

Last updated on