Notes from Ansible
List All Hosts in the Inventory File
A quick way to get a list of all the servers Ansible is aware of:
ansible -i hosts all --list-hosts
Execute Arbitrary Commands On Servers
Execute a command on a particular group in your Inventory File:
ansible -i hosts GROUP -m shell -a "uptime" For example, execute a command on all servers:
ansible -i hosts all -m shell -a "uptime" --user remote --sudo Another example, execute a command on servers in group chicago:
ansible -i hosts chicago -m shell -a "uptime" --user remote --sudo Execute a command on one server in your Inventory File:
ansible -i hosts HOSTNAME -m shell -a "uptime" For example, execute a command on server1.example.com:
ansible -i hosts server1.example.com -m shell -a "uptime" --user remote --sudo
ansible -i hosts all -m setup