# Ad‑hoc Commands **Problem** – “I need to run a quick check or command on a host without writing a full playbook.” **Solution** – Use the `ansible` command with the `-m` (module) option. | Use‑case | Command | What it does | |----------|---------|--------------| | Ping a host | `ansible host1 -m ping` | Verifies connectivity. | | List services | `ansible host1 -m shell -a 'systemctl list-units --type=service'` | Executes a shell command. | | Gather facts | `ansible all -m setup` | Collects system information. | | Run playbook file only | `ansible-playbook site.yml` | Executes the full playbook. | **Example – Quick package check** ```bash ansible web2 -m yum -a "name=nginx state=latest" ``` > **Tip** – Add `-vv` for verbose output to see command execution details.