# Failed Task for Python

**URL:** <https://forum.ansible.com/t/failed-task-for-python/4868>\
**Category:** Get Help\
**Tags:** task, ubuntu\
**Created:** [April 10, 2024, 4:51pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868 "2024-04-10T16:51:26Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 10, 2024, 4:51pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/1 "2024-04-10T16:51:26Z")

</div>

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](https://pypi.python.org/simple/%5Cn) 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

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 10, 2024, 5:18pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/2 "2024-04-10T17:18:54Z")

</div>

> [@anon99813807](#):
>
> Cannot fetch index base URL [https://pypi.python.org/simple/](https://pypi.python.org/simple/%5Cn)

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?

```bash
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

```

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 10, 2024, 5:32pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/3 "2024-04-10T17:32:53Z")

</div>

> [@Denney-tech](#):
>
> ```auto
> 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
> 
> ```

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)

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 10, 2024, 5:37pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/4 "2024-04-10T17:37:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 10, 2024, 5:43pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/5 "2024-04-10T17:43:16Z")

</div>

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](https://github.com/pypi/warehouse/issues/3654) 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.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 10, 2024, 5:55pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/6 "2024-04-10T17:55:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 10, 2024, 5:58pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/7 "2024-04-10T17:58:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 10, 2024, 11:26pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/8 "2024-04-10T23:26:12Z")

</div>

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

**Cannot fetch index base URL [https://pypi.python.org/simple/\n](https://pypi.python.org/simple/%5Cn)**

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.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 10, 2024, 11:43pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/9 "2024-04-10T23:43:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 11, 2024, 12:37pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/10 "2024-04-11T12:37:22Z")

</div>

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

I am going to just continue with the lessons.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 11, 2024, 2:21pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/11 "2024-04-11T14:21:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 11, 2024, 5:15pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/12 "2024-04-11T17:15:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 12, 2024, 5:15pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/13 "2024-04-12T17:15:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 12, 2024, 5:38pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/14 "2024-04-12T17:38:00Z")

</div>

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](https://docs.ansible.com/ansible/latest/porting_guides/porting_guides.html) that may help.

---

<div class="post-metadata">

**Author:** ![anon99813807](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anon99813807](https://forum.ansible.com/u/anon99813807)\
**Post date:** [April 12, 2024, 6:19pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/15 "2024-04-12T18:19:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 12, 2024, 6:37pm UTC](https://forum.ansible.com/t/failed-task-for-python/4868/16 "2024-04-12T18:37:02Z")

</div>

> [@anon99813807](#):
>
> fatal: [web03]: FAILED! =\> {“changed”: false, “cmd”: [“/var/www/demo/.venv/bin/pip2”, “install”, “-r”, “/var/www/demo/requirements.txt”]

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.

> [@anon99813807](#):
>
> ```yaml
> - hosts: webserver
> become: true
> tasks:
> - name: install web componants
> apt: name=[‘apache2’, ‘libabache2-mod-wsgi’, ‘python-pip’, ‘python-virtualenv’] 
> state=present update_cache=yes
> 
> ```

Try

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

```
