## Modules: Run Commands

If Ansible doesn't have a module that suits your needs there are the “run command” modules:

- command: Takes the command and executes it on the host. The most secure and predictable.
- shell: Executes through a shell like `/bin/sh` so you can use pipes etc. Be careful.
- raw: Executes a command without going through the Ansible module subsystem.

NOTE: Unlike standard modules, run commands have no concept of desired state and should only be used as a last resort.

"Run commands" are what we collectively call these modules that enable users to do command-line operations in different ways. They’re a great catch all mechanism for getting things done, but they should be used sparingly and as a last resort. The reasons are many and varied.

The overuse of run commands is common amongst those just becoming familiar with Ansible for automating their work. They use `shell` to fire off a bash command they already know without stopping to look at the Ansible docs. That works well enough initially, but it undermines the value of automating with Ansible and sets things up for problems down the road. As a best practice, always check the hundreds of Ansible shipping modules for what you need and use those first and run commands as a last resort.

NOTE: `shell` allows for IO redirection such as pipes. This is why It's best practice to use `command` unless they need to pipe something. It also best practice to never pass user input or variables thru a run command.