Thursday, April 16, 2015

Install Ansible :
Great tool for cluster mgmt
http://docs.ansible.com/intro_installation.html
note:make sure that all of your hosts are ssh via key



Install on Centos:


#sudo yum install ansible

go to the  /etc/ansible/hosts and edit it like the following example:


# This is the default ansible 'hosts' file.
# # It should live in /etc/ansible/hosts 
# # - Comments begin with the '#' character 
# - Blank lines are ignored 
# - Groups of hosts are delimited by [header] elements 
# - You can enter hostnames or ip addresses 
# - A hostname/ip can be a member of multiple groups 
# Ex 1: Ungrouped hosts, specify before any group headers. 
#green.example.com 
10.20.0.2 

[servers]  
10.20.0.3 
10.20.0.4 
10.20.0.5 
10.20.0.6 
10.20.0.7 
10.20.0.8 

 
[computes] 
10.20.0.4 
10.20.0.5 
10.20.0.6 
10.20.0.7 
10.20.0.8 

[mesos] 
111.111.111.15 
111.111.111.16 
 

Now to run a command:

example #1 run cmd on all servers

#ansible all -a "date"
10.20.0.4 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.6 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.7 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.5 | success | rc=0 >> 
Thu Apr 16 10:18:27 UTC 2015 
10.20.0.8 | success | rc=0 >> 
Thu Apr 16 10:18:28 UTC 2015
10.20.0.2 | success | rc=0 >> 
Thu Apr 16 10:18:28 UTC 2015 
111.111.111.16 | success | rc=0 >>
Thu Apr 16 10:18:28 UTC 2015
111.111.111.15 | success | rc=0 >>
Thu Apr 16 10:18:28 UTC 2015
10.20.0.3 | success | rc=0 >> 
Thu Apr 16 10:18:28 UTC 2015




example #2 run hostname cmd on all servers


# ansible computes -a "hostname" 
10.20.0.8 | success | rc=0 >> 
node-6.domain.tld 
10.20.0.4 | success | rc=0 >> 
node-2.domain.tld 
10.20.0.6 | success | rc=0 >> 
node-4.domain.tld 
10.20.0.7 | success | rc=0 >> 
node-5.domain.tld 
10.20.0.5 | success | rc=0 >> 
node-3.domain.tld