Skip to content

Instantly share code, notes, and snippets.

@felipe3dfx
Created February 20, 2018 15:47
Show Gist options
  • Save felipe3dfx/8ea59642dd9653a6cc42722e5db21473 to your computer and use it in GitHub Desktop.
Save felipe3dfx/8ea59642dd9653a6cc42722e5db21473 to your computer and use it in GitHub Desktop.
Ansible ad-hoc

Running adhoc commands on multiple servers

Example host file

Using the following /etc/ansible/hosts file:

[app]
192.168.60.4  ansible_user=deploy
192.168.60.5  ansible_user=deploy

[db]
192.168.60.6  ansible_user=deploy¬

Running commands

By default ansible will run your commands in parallel using multiple process forks. To check the host name

ansible all -a "hostname"
To Run Commands in sequence (A single process fork)
ansible all -a "hostname" -f 1

It is rare that you will need to do that the number of forks will usually be around -f 10 or f -20

Other Commands

Disk space:

ansible all -a "df -h"

Free memory:

ansible all -a "free -m"

Date and Time:

ansible all -a "date"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment