In an Ansible ad-hoc command, the pattern is defined as the host or group of hosts that you want to target from your inventory. It specifies which machines the command will be executed on.
For example, if you want to target all hosts in your inventory, you would use all as the pattern. If you have defined groups in your inventory, you can use the group name as the pattern.
Here’s a basic structure of an ad-hoc command with the pattern:
ansible [pattern] -m [module] -a "[module options]"
Examples:
- To target all hosts:
ansible all -m ping - To target a specific group (e.g.,
webservers):ansible webservers -m ping
This allows you to execute commands on specific hosts or groups as defined in your inventory file.
