Friday, October 02, 2015

Ansible Installation Details

These are the steps I followed to get going with Ansible.


Step 1: Make sure everything is up-to-date with Ubuntu Machine

$ sudo apt-get update
$ sudo apt-get upgrade

Step 2: Install Python tools (please install python first)

$ sudo apt-get install build-essential
$ sudo apt-get install python-software-properties
$ sudo apt-get install python-dev
$ sudo apt-get install python-setuptools
$ sudo easy_install pip

Step 3: Install Virtual Environment and Create an Environment for Ansible

$ sudo pip install virtualenvwrapper
$ source "/usr/local/bin/virtualenvwrapper.sh"
$ mkvirtualenv ansible-env

Step 4: Install Ansible

If you are not already in the "ansible-env" virtual environment please type the following workon command.
$ workon ansible-env
(ansible-env)$ pip install ansible

Step 5: Test Ansible Installation (ref)

(ansible-env)$ ansible all -i 'localhost,' -c local -m ping

If you see this output, you are all set.
localhost | success >> {
    "changed": false, 
    "ping": "pong"
}

Now create an inventory file and start writing playbooks.

Extra:
Run playbook locally by using the following command (ref),
$ ansible-playbook -i my-inventory install-java.yml -u --ask-sudo-pass

Make sure to mark the connection as local in your inventory (my-inventory),
[local]
localhost ansible_connection=local

Appendix
The following shell script can create a virtual environment in your Ubuntu machine which already has Python installed (ref1 and ref2).

############################
# Install basic python tools
############################

sudo apt-get install build-essential python-software-properties python-dev python-setuptools

###############################################
# Install First Virtual Environment - bootstrap
###############################################

# Name your first "bootstrap" environment:
# http://stackoverflow.com/a/5177027

INITIAL_ENV=bootstrap
# Set to whatever python interpreter you want for your first environment:
PYTHON=$(which python)

# --- Real work starts here ---
# Get the latest stable version of the virtual env

curl -Lo virtualenv-tmp.tar.gz 'https://github.com/pypa/virtualenv/tarball/master'
# The download from Github will have a strange name, so rename it
# http://unix.stackexchange.com/a/11019

mkdir virtualenv-tmp && tar xzf virtualenv-tmp.tar.gz -C virtualenv-tmp --strip-components 1
# Create the first "bootstrap" environment
$PYTHON virtualenv-tmp/virtualenv.py $INITIAL_ENV
# Don't need this anymore
rm -rf virtualenv-tmp
# Install virtualenv into the environment
$INITIAL_ENV/bin/pip install virtualenv-tmp.tar.gz

# Ativate bootstrap environment
# source $INITIAL_ENV/bin/activate

# Create a second environment from the first:
# $INITIAL_ENV/bin/virtualenv py-env1
# Create more:
# $INITIAL_ENV/bin/virtualenv py-env2


 
 

1 comment:

Tung Nguyen said...

Thank you for this post. I had some errors after running "pip install ansible"
Some ffi and openssl are missing in my lubuntu box.
I solved it by
sudo apt-get install libffi-dev
sudo apt-get install libssl-dev


(c) Jyotirmaya Nanda 2012