Failed Task for Python

Working through a Ansible course on Udemy where the instructor or pretty much anyone is helping with Q&A.

I am in a section where I am doing more and more with .yml files. First few steps working good. I am running into 2 problems. One I am not worried about so far but will list below. This first one is keeping me from proceeding.

Environment is 3 Ubuntu VM’s:
control
db02 (a database server)
web03 (a web server, Apache/2.4.7 (Ubuntu), Python 2.7.6)

For the webserver the instructor has provided a simple web application which seems to have been successfully passed to the webserver with tasks copy demo web source and copy apache virtual host config

my webserver yml is as follows:


- hosts: webserver
** become: true**
** tasks:**
** - name: install web components**
** apt: name={{item}} state=present update_cache=yes**
** with_items:**
** - apache2**
** - libapache2-mod-wsgi**
** - python-pip**
** - python-virtualenv**

** - name: ensure apache2 started**
** service: name=apache2 state=started enabled=yes**

** - name: ensure mod_wsgi enabled**
** apache2_module: state=present name=wsgi**
** notify: restart apache2**

** - name: copy demo app source**
** copy: src=/home/ansible/demo/app/ dest=/var/www/demo mode=0755**
** notify: restart apache2**

** - name: copy apache virtual host config**
** copy: src=/home/ansible/demo/demo.conf dest=/etc/apache2/sites-available mode=0755**
** notify: restart apache2**

** - name: setup python virtualenv**
** pip: requirements=/var/www/demo/requirements.txt virtualenv=/var/www/demo/.venv**
** notify: restart apache2**

** handlers:**
** - name: restart apache2**
** service: name=apache2 state=restarted**

All but the setup python virtualenv task is working correctly. That task is kicking this error:

**TASK [setup python virtualenv] **
fatal: [web03]: FAILED! => {“changed”: false, “cmd”: [“/var/www/demo/.venv/bin/pip2”, “install”, “-r”, “/var/www/demo/requirements.txt”], “msg”: “stdout: Downloading/unpacking Flask==0.10.1 (from -r /var/www/demo/requirements.txt (line 1))\n Cannot fetch index base URL https://pypi.python.org/simple/\n Could not find any downloads that satisfy the requirement Flask==0.10.1 (from -r /var/www/demo/requirements.txt (line 1))\nCleaning up…\nNo distributions at all found for Flask==0.10.1 (from -r /var/www/demo/requirements.txt (line 1))\nStoring debug log for failure in /root/.pip/pip.log\n”}

I looked on the webserver. All the files seem to be there. Not sure what is going on.

Thanks

Considering you’re trying to download a decade old version of Flask, I suspect your ubuntu VM might be using too old of a version of openssl to support TLS v1.2

From web03, can you try running the following and show us the output?

lsb_release -a
dpkg -l | egrep '^openssl'
openssl s_client -connect pypi.python.org:443
openssl s_client -connect pypi.org:443
openssl s_client -connect files.pythonhosted.org:443
1 Like

I just downloaded the version of Ubuntu this week. I think I downloaded an older version that the instructor was using.

ansible@web03:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.6 LTS
Release: 14.04
Codename: trusty

ansible@web03:~$ dpkg -l | egrep ‘^openssl’
No return for this command

The other three commands resulted in timeouts with the following code:
Timeout : 300 (sec)
Verify return code: 20 (unable to get local issuer certificate)

When I log into the server I see:

New release ‘16.04.7 LTS’ available.
Run ‘do-release-upgrade’ to upgrade to it.

Maybe I should update the 3 servers? Hope that won’t “break” anything i have done so far.

Okay, either you don’t have openssl or I fudged the command. I don’t have an ubuntu vm handy to test.

Anyways, you’re likely running into the same issue here that I found. Doing the release upgrade will probably help, and do sudo apt-get install python-minimal afterwards just in case.

I don’t guarantee it will work though, considering you’re working with decade old software.

lol yea thanks. I will look a little more for the openssl or try an update.

Just found the version
OpenSSL 1.0.1f 6 Jan 2014

Yea a bit old lol. i will try to update it.

Problem with these Udemy courses is it is very difficult to see how old they are or if they are still supported i.e getting questions answered by anyone even another student that is working the same issues. Seems I am the only person in the world doing the course right now lol.

I ran sudo apt-get install openssl and get

Reading package lists… Done
Building dependency tree
Reading state information… Done
openssl is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Something else I was wondering is what does this point to?

Cannot fetch index base URL https://pypi.python.org/simple/\n

What does the \n represent? Maybe the item that was being used is not present anymore? Where would that even be in the files I have on the webserver?

What ends up happening is when this is loaded on the webserver is running curl web03 you should see “Hello from sunny web03” vice the default Apache which I do see ok when doing curl web03.

That’s an escaped newline character \n. There’s a few of them in your output, and it isn’t part of the url. The forum just didn’t distinguish it from the url.

How hard would it be to substitute another small Python program for this?

I am going to just continue with the lessons.

The main issue is that openssl is too old to trust modern security encryption standards, and it’s already as up-to-date as it can get on Ubuntu 14.04. You can probably get away with just running do-release-upgrade to upgrade the VM’s to Ubuntu 16.04 and trying again. As long as you still have python2 available after the upgrade, it wouldn’t hurt to try again.

Learning Ansible is great, but learning how systems work and troubleshooting problems are also good skills and experience to have.

lol, thanks. I am getting my fill of it with several new issues that have come up, maybe all related to this issue. I am just moving forward with the lessons and doing what I can but keep going back to trying to fix stuff lol.

I do have another I will ask about later.

1 Like

I am running into too many issues so I am going to restart with fresh VM’s updated.

What version of Ubuntu is recommended:

Standard support

LTS Releases

  • [Ubuntu 24.04 LTS (Noble Numbat) Beta ›]
  • [Ubuntu 22.04.4 LTS (Jammy Jellyfish) ›]
  • [Ubuntu 20.04.6 LTS (Focal Fossa) ›

Interim Releases

  • [Ubuntu 23.10 (Mantic Minotaur) ›]

Extended Security Maintenance (ESM)

  • [Ubuntu 18.04.6 LTS (Bionic Beaver) ›
  • [Ubuntu 16.04.7 LTS (Xenial Xerus) ›
  • [Ubuntu 14.04.6 LTS (Trusty Tahr) ›]

I already had 14.04.6 LTS as that is what the course was using.

How about ansible version? To get that on the VM I used the commands per the course directions to setup lab:

sudo apt-get install software-properties-common

sudo apt-add-repository ppa:ansible/ansible

sudo apt-get update

sudo apt update

sudo apt upgrade

sudo apt-get install ansible

Try 20.04. You’ll need to install python2 from the universe repo, but it is still available there to support older packages in universe that still depend on it. The OS is new enough that it should allow the course’s project to install package requirements from pypi.org.

Ansible on the other hand will probably be newer, so your mileage may vary here. There’s a good chance it could work as is since the Ansible devs try to maintain backwards compatibility where possible, but you there is a possibility you might have to make changes to the ansible-related course material. There’s a number of porting guides that may help.

How about python3?

Python I guess is loaded here as one of the lab lessons?


  • hosts: webserver
    become: true
    tasks:
    • name: install web componants
      apt: name={{item}} state=present update_cache=yes
      with_items:
      • apache2
      • libapache2-mod-wsgi
      • python-pip
      • python-virtualenv

Speaking of that section. When I was running this before that is one of the “issues” I had as deprecated but appeared to still complete. I got this alert:

[DEPRECATION WARNING]: Invoking “apt” only once while using a loop via squash_actions is deprecated. Instead of using a loop to
supply multiple items and specifying name: "{{item}}", please use name: ['apache2', 'libapache2-mod-wsgi', 'python-pip',** **'python-virtualenv'] and remove the loop. This feature will be removed in version 2.11.

I had tried to reformat the .yml file per what I thought that message said but got an error:


  • hosts: webserver
    become: true
    tasks:
    • name: install web componants
      apt: name=[‘apache2’, ‘libabache2-mod-wsgi’, ‘python-pip’, ‘python-virtualenv’] state=present update_cache=yes

This is why I was recommending python2. That’s specifically what the demo is using. There’s no guarantee that the project will work in python3 even if you made the effort to have it install in a python3 enabled venv.

Try

- hosts: webserver
  become: true
  tasks:
    - name: install web componants
      apt:
        name:
          - apache2
          - libabache2-mod-wsgi
          - python-pip
          - python-virtualenv
        state: present
        update_cache: yes