Install Ansible

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

Getting ready

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.

How to do it…

In this recipe, 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
    
    Installing cutting edge from Git
  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
    

There's more…

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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset