Ansible for Network Engineers · Ansible 1

Ansible from zero: control node, inventory, ad-hoc commands and a first playbook

Set up a real Linux control node for your routers and switches: an inventory with groups, an ansible.cfg, the host key question every beginner hits, ad-hoc commands, and a first playbook that you dry-run, apply, and run again to see idempotency with your own eyes.

49 min read11 chapters4 labs15 quiz7 scenarios15 interview Q&A

This first module is free: read the lesson and take the quiz. Labs need an account: sign up free to run up to 3 hands-on labs.

Log inStart free trial
This reading material cannot be printed. Read it on config.nwkings.com.
01

Welcome to Ansible: what you will learn and the big picture

What you will learn in this module. This is your first step into network automation with Ansible, and you do not need any earlier experience. By the end you will have built a working control node, described three real devices in an inventory, talked to them with ad-hoc commands, written a playbook, dry-run it, applied it, and proved that running it again changes nothing. You will also learn the short list of errors every beginner meets and how to read them.

  • What Ansible is, what "agentless" means, and why network engineers use it.
  • The control node, ansible-core, collections and fully qualified module names.
  • An inventory with groups and the variables that tell Ansible how to log in.
  • ansible.cfg and the SSH host key question.
  • Ad-hoc commands: ping, ios_command, ios_facts, ios_config.
  • YAML and your first playbook, line by line, with --check, --diff and idempotency.

Prerequisites. You should be able to type basic Linux commands (cd, ls, cat) and know what an SSH login and an ntp server line on a router are. You do not need Python, YAML or any Ansible knowledge. Everything is explained from zero.

Analogy: a tireless assistant with a checklist

Imagine you must add the same NTP server to fifty routers tonight. By hand you would open fifty SSH sessions, type the same line fifty times and hope you never mistype. Now imagine a tireless assistant who reads your checklist, logs in to each router exactly as you would, types the commands, and reports "done" or "already there" for every device. That assistant is Ansible. You write the checklist (a playbook) and the list of devices (an inventory); Ansible does the typing.

AUTO01control node (Linux)10.99.0.60 R1 PUN-CORE-R110.99.0.1 R2 BLR-EDGE-R210.99.0.2 SW1 PUN-ACC-SW110.99.0.10 SSH (port 22), nothing installed on devices

Ansible runs on one Linux box and logs in to every device over SSH, the same way you do.

The words you will meet

Control node
The Linux machine where Ansible is installed and where you run commands. In our lab it is AUTO01.
Managed node
Any device Ansible manages: here two routers and a switch.
Agentless
Nothing is installed on the managed node. Ansible only needs the SSH login that you already use.
Inventory
A file that lists the devices and how to reach them.
Module
A ready-made worker for one job, for example cisco.ios.ios_config sends configuration lines.
Task, play, playbook
A task calls one module. A play says which hosts run a list of tasks. A playbook is a file holding one or more plays.
Idempotent
Running the same playbook twice gives the same end state, and the second run changes nothing.

Worked example. The Network Kings lab has R1 in Pune (10.99.0.1), R2 in Bengaluru (10.99.0.2) and the access switch SW1 (10.99.0.10). Adding ntp server 10.99.0.60 by hand means three logins. With Ansible it is one command: ansible-playbook ntp.yml. With three devices the saving is small; with three hundred it is the difference between a night and a minute.

Why network engineers like Ansible

  • No agent, no daemon: routers and switches cannot run agents anyway. Ansible uses SSH and the normal CLI.
  • Readable: a playbook is plain YAML text that a colleague can review like a change ticket.
  • Safe by design: you can dry-run, you can limit a run to one device, and good modules only send what is missing.
  • One tool, many vendors: the same ideas work for Cisco IOS, Junos, NX-OS and Linux servers.

Common beginner mistake. Thinking Ansible must be installed on the routers, or that it "pushes a program" to them. It does not. If you can SSH to a device from the control node, Ansible can manage it. Another trap: running a playbook against all devices on day one. You will learn to limit and dry-run first.

Exam trap. Interviewers ask "is Ansible agent-based?" The answer is no: it is agentless and push-based over SSH (or an API). The control node must be Linux or macOS; Windows is not supported as a control node.

The 2 AM NTP change

A bank branch network of forty routers had a retired NTP server. The engineer on call logged in to each router by hand. By router 28 he mistyped an IP address, and logs on that router were stamped with the wrong time for a week. The team later wrote a playbook with one NTP variable. The next time the server changed, one edit and one run updated all forty devices and the recap showed which ones were already correct.

Lesson: automation is not about speed alone; it removes typing mistakes and gives you a record of what changed.

"What is Ansible and why is it agentless?"

Ansible is an open-source automation tool. You describe the desired state in YAML playbooks and an inventory; the control node connects over SSH (or an API), runs modules, and reports ok, changed or failed per device. It is agentless because network devices cannot host an agent, so it reuses the management access you already have. Mention idempotency and the inventory/playbook split to show you understand the model.

Key takeaways

  • Ansible runs on a Linux control node and manages devices over SSH with nothing installed on them.
  • The inventory says which devices; the playbook says what to do.
  • A module does one job; a task calls a module; a play targets hosts; a playbook holds plays.
  • Idempotent means a second run changes nothing.
  • Our lab: AUTO01 manages R1, R2 and SW1 on 10.99.0.0/24.

Upgrade to keep reading

The free plan lets you read chapter 1 of this module. Upgrade to open the remaining chapters.

  1. Your control node: Linux, ansible-core, collections and module names
  2. The inventory: telling Ansible which devices exist and how to log in
  3. ansible.cfg and the host key question every beginner meets
  4. Ad-hoc commands: your first conversations with the devices
  5. YAML from zero: the file format behind every playbook
  6. YAML and your first playbook, line by line
  7. Dry run, apply, run again: reading the recap, idempotency and saving
  8. Reading Ansible output: ok, changed, failed and the recap
  9. Troubleshooting your first runs: a workflow for red text
  10. Summary and exam checklist

Join the community