Ad-hoc Commands
Ad-hoc is the concept of one-time Ansible commands.
You run a command on the inventory and a group, or even on specific hosts, to perform a one-time action.
Why Use Ad-hoc
These commands are useful for:
- quick checks
- one-time actions
- tasks that do not need a full playbook flow yet
Example (From CLI)
ad-hoc
ansible OSPFrouters -i inventory.ini -m cisco.ios.ios_banner -a "banner=motd text='test' state=present"
One-shot banner push to the OSPFrouters group. No playbook.
Another quick operational example:
ad-hoc
ansible routers -i inventory.ini -m cisco.ios.ios_command -a 'commands=["show clock"]'
Run a show command on every host in routers.
Syntax Pattern
pattern
ansible -i -m -a ''</code>
Target, inventory, module, args. Same shape every time.
</div>