Ansible : How to Install Ansible

0
1

What is Ansible ?

Ansible is an easy-to-use agentless system configuration management tool. It allows us to deploy complex configurations without the hassle of a complex interface or language.

Ansible uses playbooks, which are collections of tasks to deploy configurations and applications to multiple nodes over SSH in a controlled way. However, it doesn’t stop there.

Ansible’s modules, which are used to execute tasks, are all built to be idempotent in their execution. In short, any module will detect the changes to be applied and perform them. If it doesn’t need to change anything, it will not reapply the requested changes or interfere with file metadata.

The Ansible company also provides Tower, a paid subscription with extra features, as an add-on to Ansible. Tower provides a graphical interface to control your Ansible orchestration tool.

Install Ansible

Ansible is not in the default RHEL 7 repositories, but in this tutorial, I will show you how to install it in several ways.

Ansible needs the following packages installed:

  • Python v2.7 (Ansible doesn’t support v3 yet)
  • python-httplib2
  • python-jinja2
  • python-paramiko
  • python-setuptools
  • PyYAML

So, in order to achieve this, execute the following command:

~]# yum install -y python-httplib2 python-jinja2 python-keyczar python-paramiko python-setuptools PyYAML

As RHEL 7 and some other major distributions come preinstalled with Python (yum requires it, as do most of the Red Hat tools), we don’t have to include it in the preceding command.

In this tutorial, I will cover the three most used methods of installing Ansible.

INSTALLING THE LATEST TARBALL

This method is quite simple as you just download the tarball and extract it in a location of your choosing. Perform the following steps:

  1. Grab the latest tarball located at http://releases.ansible.com/ansible/ via the following command:
    ~]$ curl -o /tmp/ansible-latest.tar.gz http://releases.ansible.com/ansible/ansible-latest.tar.gz
     % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  905k  100  905k    0     0   870k      0  0:00:01  0:00:01 --:--:--  870k
    ~]$
    
  2. Extract the tarball to /opt, as follows:
    ~]# tar zxf /tmp/ansible-latest.tar.gz -C /opt/
    
  3. Now, create a symbolic link for easy access using this command:
    ~]# ln -s /opt/ansible-1.9.2 /opt/ansible
    
  4. Add the Ansible binaries and man pages to your environment’s path by executing the following:
    ~]# cat << EOF > /etc/profile.d/ansible.sh
    # Ansible-related stuff
    export ANSIBLE_HOME=/opt/ansible
    export PATH=\${PATH-""}:${ANSIBLE_HOME}/bin
    export MANPATH=\${MANPATH-""}:${ANSIBLE_HOME}/docs/man
    export PYTHONPATH=\${PYTHONPATH-""}:${ ANSIBLE_HOME}/lib
    EOF
    ~]#
    
  5. Next, source the Ansible PATH and MANPATH by running this command line:
    ~]# . /etc/profile.d/ansible.sh
    
  6. Finally, use the following command to regenerate the man pages:
    ~]# /etc/cron.daily/man-db.cron
    

INSTALLING CUTTING EDGE FROM GIT

Git makes keeping your local copy of Ansible up to date quite simple.

It automatically updates/removes files where needed. Perform the following steps:

  1. Make sure git is installed using this command:
    ~]# yum install -y git
    
  2. Clone the Ansible git repository to /opt, as follows:
    ~]# cd /opt
    ~]# git clone git://github.com/ansible/ansible.git --recursive
    
  3. Add the Ansible binaries and man pages to your environment’s path, through the following command:
    ~]# cat << EOF > /etc/profile.d/ansible.sh
    # Ansible-related stuff
    export ANSIBLE_HOME=/opt/ansible
    export PATH=\${PATH-""}:${ANSIBLE_HOME}/bin
    export MANPATH=\${MANPATH-""}:${ANSIBLE_HOME}/docs/man
    export PYTHONPATH=\${PYTHONPATH-""}:${ ANSIBLE_HOME}/lib
    EOF
    ~]#
    
  4. Now, source the Ansible PATH and MANPATH via this command:
    ~]# . /etc/profile.d/ansible.sh
    
  5. Finally, using the following line, regenerate the man pages:
    ~]# /etc/cron.daily/man-db.cron
    

INSTALLING ANSIBLE FROM THE EPEL REPOSITORY

Installing from a repository has the advantage that you can keep your version of Ansible up to date along with your system. Here are the steps you need to perform:

  1. Install the extra packages for the Enterprise Linux (EPEL) repository from https://fedoraproject.org/wiki/EPEL via this command:
    ~]# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    
  2. Now, install Ansible using yum, as follows:
    ~]# yum install -y ansible
    

If you want to keep your Git clone up to date, remember that the sources tree also contains two subtrees. You’ll have to execute the following:

~]# git pull --release
~]# git submodule update --init --recursive

LEAVE A REPLY

Please enter your comment!
Please enter your name here