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. 

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.

# Written by in April 2017.  Updated in June of 2018.
yum -y update
yum -y install gcc git java python-devel java

cd /bin
curl -L "" -o ""


curl -L $short > /bin/paramiko-1.16.0.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 build
python install
cd /bin/
tar -xvf pycrypto-2.6.1.tar.gz
cd pycrypto-2.6.1
python build
python install

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


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

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

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

pip install boto3

curl -L$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' ]
  echo "Installation of Maven has failed.  Check the source of the URL of the apache-maven-$mvnversion-bin.tar.gz file."

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. Required fields are marked *