Home > Linux, Redhat, Virtualization > Ansible Installation and Configuration

Ansible Installation and Configuration

Working on an OEL 6.2, this was the quickest way to get Ansible running:

Reference for all material:

## Download & Install EPEL RPM for your major release:

wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm

## Install Ansible using yum

yum install ansible

## Set up initial hosts

cd /etc/ansible/
cp hosts hosts.orig

## Edit host file

vi /etc/ansible/hosts

## remote, will call all children hosts in group

## variables to be used later

cm-dev-01 nickname=engineering vm=1
cm-test-01 nickname=engineering vm=1

## shortcut for 01,02,03

## Alias example
# jumper ansible_port=5555 ansible_host=

## Edit Ansible config to not check SSH host key

vi /etc/ansible/ansible.cfg

# uncomment this to disable SSH key host checking
host_key_checking = False


## Copy ssh key from Ansible server to all clients
# If necesseary, create your RSA keys

ssh-keygen -t rsa
 ssh-copy-id -i ~/.ssh/id_rsa.pub <user>@<host>

## Very basic ping to check all is in order

ansible all -m ping
 ansible engineering -m ping
 ansible costamesa -m ping

## Ansible variables can be defined in the var 

## Pattern usage, using [all|*] is equivalent; the “:” separates groups, like OR
## Intersection of multiple groups uses “&engineering”, or use “!engineering” for NOT
## Ansible is very flexible here in its use of regex and globs
Reference: http://docs.ansible.com/ansible/intro_patterns.html
ansible <pattern_goes_here> -m <module_name> -a <arguments>
ansible webservers -m service -a “name=httpd state=restarted”
ansible engineering:sit-servers -m service -a “name=httpd state=restarted”
Ex: one*.com:dbservers ; webservers:&staging

## Ad-hoc commands, forking in parallel, 5 is default, memory is the constraint
ansible atlanta -a “/sbin/reboot” -f 10

## Using other user than you logged in as
ansible atlanta -a “/usr/bin/foo” -u username –sudo [–ask-sudo-pass]

## Commands entered do not source ENV variables. If you wish to run it as you would in a shell
ansible raleigh -m shell -a ‘echo $TERM’

## Quick copy
ansible atlanta -m copy -a “src=/etc/hosts dest=/tmp/hosts”

## Allowing for file property manipulation
ansible webservers -m file -a “dest=/srv/foo/b.txt mode=600 owner=<uid> group=<group>”

 ## Create, delete directory recursively
ansible webservers -m file -a “dest=/path/to/c mode=755 owner=<uid> group=<gid> state=directory”
ansible webservers -m file -a “dest=/path/to/c state=absent”






Categories: Linux, Redhat, Virtualization
  1. January 29, 2016 at 5:36 am

    It would be appropriate to put your bash code within tags: https://en.support.wordpress.com/code/posting-source-code/

  2. January 29, 2016 at 6:19 am

    Thanks, I’ll change it for readability.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: