Install, inventory & ad-hoc commands

Hosts, groups, and one-off tasks.

Beginner12 min · lesson 2 of 12

Ansible installs as a Python package on the control node only — pip install ansible, and you are ready; the managed hosts get nothing. The first thing you define is inventory: a list of the hosts you manage, organized into groups (webservers, dbservers) so you can target them collectively. Inventory can be a simple INI or YAML file to start, and later a dynamic source that queries your cloud.

inventory.ini
[web]
web1.acme.internal
web2.acme.internal
[db]
db1.acme.internal
[prod:children] # a group of groups
web
db
[web:vars]
ansible_user=deploy

Ad-hoc commands

Before playbooks, the quickest way to use Ansible is an ad-hoc command: run a single module against a group right now. ansible <group> -m <module> -a <args> is perfect for one-off tasks — check connectivity with the ping module, gather uptime, restart a service across a group. It is the same execution engine as a playbook, just one task instead of a file of them.

terminal
$ ansible web -i inventory.ini -m ping
web1.acme.internal | SUCCESS => { "ping": "pong" }
web2.acme.internal | SUCCESS => { "ping": "pong" }
$ ansible web -i inventory.ini -m service -a "name=nginx state=restarted" --become
ping is not ICMP — it tests the whole path
The ansible ping module does not send an ICMP packet; it connects over SSH and runs a tiny Python check, so a SUCCESS proves SSH auth, Python, and privileges all work — the real connectivity you need. If it fails, you are debugging SSH keys, the ansible_user, or missing Python on the target, not the network.