Pages

Thursday, October 31, 2013

Installing ansible on Centos 6

h3. Installing ansible on Centos 6

h5. ansible  dependencies

* python-babel
* PyYAML    
* python-crypto      
* python-jinja2      
* python-paramiko
* python-simplejson.x86_64 - on all nodes ( if python is lower version than 2.5 )

{code}
[root@tiber07vm1 ansible]# ansible --version
ansible 1.1
{code}


h5. Control Machine (master ) Requirements :

Currently Ansible can be from any machine with Python 2.6 installed

[root@tiber07vm1 download]# python -V
Python 2.6.6


h5. Managed Node Requirements
On the managed nodes, you only need Python 2.4 or later, but if you are are running less than Python 2.5 on the remotes, you will also need:

h5. Inventory of manged hosts:

Inventory of manged hosts will be at /etc/ansible/hosts

{code}
[root@tiber07vm1 ansible]# cat /etc/ansible/hosts
[local]
tiber07vm1

[remote]
tiber07vm3

[all:children]
local
remote

{code}

h5. First run :

{code}
[root@tiber07vm1 ansible]# ansible remote1  -a "uptime" --ask-pass
SSH password:
tiber07vm4 | success | rc=0 >>
 23:27:18 up 20 days, 11:05,  0 users,  load average: 0.00, 0.00, 0.00

{code}

h5. SSH trust : since you want pass wordless authentication from your master machine ,its advisable to establish a trust

{code}

ssh-copy-id tiber07vm1

ssh-copy-id tiber07vm3

{code}

h5. Sample run :

{code}

[root@tiber07vm1 ansible]# ansible local -a "uptime"
tiber07vm1 | success | rc=0 >>
 23:32:56 up 20 days, 11:10,  1 user,  load average: 0.04, 0.02, 0.00

[root@tiber07vm1 ansible]# ansible remote  -a "uptime"
tiber07vm3 | success | rc=0 >>
 23:33:01 up 20 days, 11:10,  0 users,  load average: 0.04, 0.02, 0.00

[root@tiber07vm1 ansible]# ansible all -a "uptime"
tiber07vm1 | success | rc=0 >>
 23:33:06 up 20 days, 11:11,  1 user,  load average: 0.03, 0.02, 0.00

tiber07vm3 | success | rc=0 >>
 23:33:07 up 20 days, 11:11,  0 users,  load average: 0.03, 0.02, 0.00


{code}

Tuesday, October 29, 2013

Bash serial execution of commands and exit on critical

If you want  to executue the shell commands serially in bash script but also want to keep checking and exit if  any of the command fails

set this at the top of your script

set -e
set -o pipefail

Tuesday, October 8, 2013

Yum custom variables

While defining the your local yum repository you can use YUM's in built and custom variable, most commonly used are


$releasever
This is replaced with the package's version, as listed in distroverpkg. This defaults to the version of the redhat-release package. ( this is defined in /etc/yum.conf)
e.g rpm -q --queryformat '%{VERSION}' centos-release-5-9.el5.centos.1

$arch
This is replaced with your system's architecture, as listed by os.uname() in Python.
$basearch
This is replaced with your base architecture. For example, if $arch=i686 then $basearch=i386.
$YUM0-9
This is replaced with the value of the shell environment variable of the same name. If the shell environment variable does not exist, then the configuration file variable will not be replaced.


IF you are using Centos6 (rhel 6) you can define a custom variable or  override the value of an existing one, using file with the same name as the variable (without the $ sign) in the /etc/yum/vars/ directory, and add the desired value on its first line.

e.g. 

[root@myhost~]# cat /etc/yum/vars/releasever
6.4




Also have multilib_policy defined in your yum.conf to download the required architecure rpms only (32 bit /64 bit)

multilib_policy=best