In this blog post, I will show you how to run commands on remote machines with Ansible without using a Playbook.
Command
Runing playbooks on Ansible machines is great but sometimes you might have a use case where you just need to run a single command on your machine. Checking the uptime of a remote machine is a good example.
For that reason, Ansible gave us the command module that allows us to run commands directly on hosts.
Check Uptime
Let’s take the below example where I will use the uptime command to check a remote machine uptime.
ansible servers -i hosts -m command -a uptime
The above command is using for the host groups name and -i as for the inventory file. -m is telling Ansible to use the command module and -a is the actual command we are running.