The stuff I do

Ansible tips

← Notes

Tags: [bash][ansible]

Run a command on several hosts 🔗

The documentation Introduction to Ad Hoc commands is a great reference.

  1. In the inventory file create the list of servers to target
  1. Run the command
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.

--becomeBecome root
-u <username>Change the username used
--ask-become-pass or -KPrompts you for the password to use for privilege escalation
-f 10Change how many machines are targeted simultaneously

Copying files between hosts 🔗

Refer to this link

← Notes

Back to top