Tell Ansible which machines to manage with an inventory, then run one-off commands across them — starting with your own machine, so you need no remote servers.
Why: Ansible is agentless — it connects to machines over SSH (or runs locally), pushes small modules, executes them, and removes them. There is nothing to install on the managed machines except Python. You run everything from a "control node" (your machine); the machines it manages are "managed nodes". This course manages your own machine, so no servers are needed.
control node (you) managed nodes
────────────────── ─────────────
ansible / ansible-playbook ──SSH──▶ server A (just needs Python)
inventory + playbooks ──SSH──▶ server B
──local─▶ localhost (used in this course)Why: the inventory lists the machines Ansible can manage and groups them. The simplest form is an INI file: groups in [brackets], hosts beneath. ansible_connection=local tells Ansible to run on this machine instead of opening an SSH connection — perfect for learning.
# inventory.ini
[local]
localhost ansible_connection=local
[web]
web1.example.com
web2.example.com
[db]
db1.example.comAn ad-hoc command runs a single module against hosts without writing a playbook — great for quick checks. -m picks the module, -i points at your inventory. The ping module confirms Ansible can reach a host and run Python there; a green "pong" means you are ready.
Can Ansible reach and run on localhost?
ansible local -m ping -i inventory.iniTarget everything in the inventory
ansible all -m ping -i inventory.iniWhy: ad-hoc commands are not just for ping — any module works. -a passes arguments. Use the command module for a quick shell command, or a real module like file to make a change. This is how you do one-off tasks; playbooks (next lesson) are for anything you repeat.
Run a shell command on the targets
ansible local -m command -a "uptime" -i inventory.iniUse a module to create a directory
ansible local -m file -a "path=/tmp/demo state=directory" -i inventory.iniGather and print all facts about a host
ansible local -m setup -i inventory.ini