Follow the following commands:
$sudo apt-get update
$sudo apt-get upgrade -y
$sudo apt-add-repository ppa:ansible/ansible
$sudo apt-get update
$sudo apt-get install ansible -y
$sudo apt-get install python -y
Removing exicting python and installing python 3.7 for ansible:
$sudo apt autoremove python
$sudo apt install python3.7