Tags: [bash][ansible]
The documentation Introduction to Ad Hoc commands is a great reference.
[my_target_group_name]
host01.domain.ext
host02.domain.ext
host03.domain.ext
ansible [target_group_name] -i path/to/inventory/file -m shell -a [your_command]
# Example
ansible my_target_group_name -i inventories/inventory -m shell -a 'df -h'
The module shell
allows to run any shell command but one can use any module
If you need to become root to run the command pass --become
to the ansible
command.
Parameter | Description |
---|---|
--become | Become root |
-u <username> | Change the username used |
--ask-become-pass or -K | Prompts you for the password to use for privilege escalation |
-f 10 | Change how many machines are targeted simultaneously |
Refer to this link