Files
ansible/ad-hoc-commands.md
2026-03-24 16:13:33 +02:00

21 lines
797 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Adhoc 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.
| Usecase | 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.