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

797 B
Raw Permalink Blame History

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

ansible web2 -m yum -a "name=nginx state=latest"

Tip

Add -vv for verbose output to see command execution details.