# Buggy code
def install_prerequisites():
    # pre-requisites for bench repo cloning
    run_os_command(
        {
            "apt-get": [
                "sudo apt-get update",
                "sudo apt-get install -y git build-essential python3-setuptools python3-dev libffi-dev",
            ],
            "yum": [
                'sudo yum groupinstall -y "Development tools"',
                "sudo yum install -y epel-release redhat-lsb-core git python-setuptools python-devel openssl-devel libffi-devel",
            ],
        }
    )

    install_package("curl")
    install_package("wget")
    install_package("git")
    install_package("pip3", "python3-pip")

    success = run_os_command(
        {
            "python3": "sudo -H python3 -m pip install --upgrade setuptools cryptography ansible==2.8.5 pip"
        }
    )

    if not (success or shutil.which("ansible")):
        could_not_install("Ansible")


# Traceback (ModuleNotFoundError)
Checking System Compatibility...
ubuntu 18 is compatible!
Hit:1 http://mirror.hetzner.de/ubuntu/packages bionic InRelease
Hit:2 http://mirror.hetzner.de/ubuntu/packages bionic-updates InRelease
Hit:3 http://mirror.hetzner.de/ubuntu/packages bionic-backports InRelease
Hit:4 http://mirror.hetzner.de/ubuntu/packages bionic-security InRelease
Get:5 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Hit:6 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:7 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:8 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 88.7 kB in 2s (59.1 kB/s)
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
build-essential is already the newest version (12.4ubuntu1).
libffi-dev is already the newest version (3.2.1-8).
python3-setuptools is already the newest version (39.0.1-2).
git is already the newest version (1:2.17.1-1ubuntu0.7).
python3-dev is already the newest version (3.6.7-1~18.04).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
curl already installed!
wget already installed!
git already installed!
pip3 already installed!
Requirement already up-to-date: setuptools in /usr/local/lib/python3.6/dist-packages (50.0.0)
Requirement already up-to-date: cryptography in /usr/local/lib/python3.6/dist-packages (3.1)
Collecting ansible==2.8.5
Using cached ansible-2.8.5.tar.gz (14.4 MB)
Requirement already up-to-date: pip in /usr/local/lib/python3.6/dist-packages (20.2.2)
Requirement already satisfied, skipping upgrade: six>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from cryptography) (1.15.0)
Requirement already satisfied, skipping upgrade: cffi!=1.11.3,>=1.8 in /usr/local/lib/python3.6/dist-packages (from cryptography) (1.14.2)
Requirement already satisfied, skipping upgrade: jinja2 in /usr/local/lib/python3.6/dist-packages (from ansible==2.8.5) (2.11.2)
Requirement already satisfied, skipping upgrade: PyYAML in /usr/lib/python3/dist-packages (from ansible==2.8.5) (3.12)
Requirement already satisfied, skipping upgrade: pycparser in /usr/local/lib/python3.6/dist-packages (from cffi!=1.11.3,>=1.8->cryptography) (2.20)
Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in /usr/local/lib/python3.6/dist-packages (from jinja2->ansible==2.8.5) (1.1.1)
Using legacy 'setup.py install' for ansible, since package 'wheel' is not installed.
Installing collected packages: ansible
Running setup.py install for ansible ... done
Successfully installed ansible
Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 32, in <module>
from ansible import context
ModuleNotFoundError: No module named 'ansible'
Traceback (most recent call last):
File "install.py", line 437, in <module>
install_bench(args)
File "install.py", line 211, in install_bench
run_playbook('create_user.yml', extra_vars=extra_vars)
File "install.py", line 362, in run_playbook
success = subprocess.check_call(args, cwd=os.path.join(cwd, 'playbooks'), stdout=log_stream, stderr=sys.stderr)
File "/usr/lib/python3.6/subprocess.py", line 311, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ansible-playbook', '-c', 'local', 'create_user.yml', '-vvvv', '-e', '@/tmp/extra_vars.json']' returned non-zero exit status 1.

# Fixed code
def install_prerequisites():
    # pre-requisites for bench repo cloning
    run_os_command(
        {
            "apt-get": [
                "sudo apt-get update",
                "sudo apt-get install -y git build-essential python3-setuptools python3-dev libffi-dev",
            ],
            "yum": [
                'sudo yum groupinstall -y "Development tools"',
                "sudo yum install -y epel-release redhat-lsb-core git python-setuptools python-devel openssl-devel libffi-devel",
            ],
        }
    )

    install_package("curl")
    install_package("wget")
    install_package("git")
    install_package("pip3", "python3-pip")

    success = run_os_command(
        {
            "python3": "sudo -H python3 -m pip install --upgrade setuptools wheel cryptography ansible==2.8.5 pip"
        }
    )

    if not (success or shutil.which("ansible")):
        could_not_install("Ansible")