You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Ad-hoc commands are one-line Ansible commands that let you perform quick tasks without writing a playbook. They are ideal for testing, troubleshooting, and one-off operations. Every ad-hoc command uses a module --- the building block of all Ansible automation.
ansible <host-pattern> -i <inventory> -m <module> -a "<arguments>"
| Flag | Description |
|---|---|
-i | Path to the inventory file |
-m | The module to use |
-a | Arguments to pass to the module |
-b | Enable become (privilege escalation / sudo) |
-u | Remote user |
-k | Prompt for SSH password |
-K | Prompt for become (sudo) password |
-f | Number of parallel forks (default: 5) |
-v | Verbose output (-vv, -vvv, -vvvv for more detail) |
The ping module is the simplest way to verify connectivity --- it is not an ICMP ping, but an Ansible-level connectivity test:
# Test all hosts
ansible all -m ping
# Test a specific group
ansible webservers -m ping
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.