How Do You Install an Older Version of Ansible on an AWS Instance of Red Hat Linux?

Problem scenario
You are using Red Hat Enterprise Linux in AWS.  You need to install an older version of Ansible -- not the newest.  The pip command and other supported ways of deploying Ansible automatically use the newest version.  You also want to install Maven. 

Solution
Run this script with "sudo". (You could run it as root, but that is not recommended.)  The server must be in a Security Group with access to the internet.

#!/bin/bash
# Written by continualintegration.com in April 2017.  Updated in June of 2018.
yum -y update
yum -y install gcc git java python-devel java
mvnversion=3.5.3
ansibleversion=2.2.2.0

cd /bin
curl -L "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

short='https://pypi.python.org/packages/23/54/3a88b35388f0df0a12d8cccc3f7f80d4c689c24600dd64a100b7b3dff6c6/paramiko-1.16.0.tar.gz#md5=7e1203f5ffeb7d2bc2bffc4feb804216'

curl -L $short > /bin/paramiko-1.16.0.tar.gz

short1='https://pypi.python.org/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz'
curl -L $short1 > /bin/pycrypto-2.6.1.tar.gz
cd /bin
tar -xvf paramiko-1.16.0.tar.gz
cd paramiko-1.16.0
python setup.py build
python setup.py install
cd /bin/
tar -xvf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1
python setup.py build
python setup.py install

echo "************************************************************************************************************"
echo "  "
echo " Retrieving Ansible installation media"

ans='https://files.pythonhosted.org/packages/01/d5/b19c20595b2705d8bac61a803cecaaeb8cad4e6227df152335a18a9a0913/ansible-'$ansibleversion'.tar.gz'

curl -L $ans > /bin/ansible-$ansibleversion.tar.gz

cd /bin/
tar -xvf ansible-$ansibleversion.tar.gz
cd ansible-$ansibleversion
python setup.py build
python setup.py install

echo "************************************************************************************************************"
echo "  "
echo " Ansible installation attempted earlier.  Now moving on to install boto3 and Maven..."

pip install boto3

curl -L http://ftp.wayne.edu/apache/maven/maven-3/$mvnversion/binaries/apache-maven-$mvnversion-bin.tar.gz > /bin/apache-maven-$mvnversion-bin.tar.gz

md=$(md5sum /bin/apache-maven-$mvnversion-bin.tar.gz | awk '{print $1}')
if [ $md -ne '35c39251d2af99b6624d40d801f6ff02' ]
then
  echo "Installation of Maven has failed.  Check the source of the URL of the apache-maven-$mvnversion-bin.tar.gz file."
  exit
fi

cd /bin
tar -xvf apache-maven-$mvnversion-bin.tar.gz
mkdir -p /usr/local/apache-maven
mv /bin/apache-maven-$mvnversion/* /usr/local/apache-maven

cp /root/.bash_profile /root/bak.bash_profile.bak
echo "Do NOT run this script twice b/c the .bash_profile file will get duplicate entries."
echo "export M2_HOME=/usr/local/apache-maven" >> /root/.bash_profile
echo "export M2=\$M2_HOME/bin" >> /root/.bash_profile
echo "export PATH=\$M2:\$PATH" >> /root/.bash_profile

source ~/.bashrc

echo 'check the ansible version with $(ansible --version)'
echo 'To check the Maven version, you need to exit the root user and resume the session as the root user'
echo 'Then run $(mvn -version) as the root user'

Leave a comment

Your email address will not be published.