# Python not found in Ubuntu 16.04 server

**URL:** <https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [April 24, 2016, 7:00pm UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252 "2016-04-24T19:00:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Loron](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@Peter\_Loron](https://forum.ansible.com/u/Peter_Loron)\
**Post date:** [April 24, 2016, 7:00pm UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252/1 "2016-04-24T19:00:55Z")

</div>

I’m trying to provision a Ubuntu 16.04 server machine. When running a playbook which has worked fine on Ubuntu 14.x and 15.x, it fails with this error:

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [foo]: FAILED! =\> {“changed”: false, “failed”: true, “module\_stderr”: “”, “module\_stdout”: “/bin/sh: 1: /usr/bin/python: not found\r\n”, “msg”: “MODULE FAILURE”, “parsed”: false}

Ubuntu 16.04 has python3, not 2.7.x. Why is this not being autodetected?

---

<div class="post-metadata">

**Author:** ![Andreas\_Olsson](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Andreas\_Olsson](https://forum.ansible.com/u/Andreas_Olsson)\
**Post date:** [April 24, 2016, 7:38pm UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252/2 "2016-04-24T19:38:03Z")

</div>

No Ansible support for Python 3 just yet.

&nbsp;&nbsp;[https://docs.ansible.com/ansible/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine](https://docs.ansible.com/ansible/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine)

For Ubuntu 16.04 I use the following play to get Python 2.7 installed.

&nbsp;&nbsp;- hosts: xenials  
gather\_facts: False  
tasks:  
- name: apt-get update  
raw: apt-get update -qq  
- name: Install python 2.7  
raw: apt-get install -qq python2.7

That provides an /usr/bin/python2.7, which I explicitly point to in my  
inventory file.

&nbsp;&nbsp;[xenials:vars]  
&nbsp;&nbsp;ansible\_python\_interpreter=/usr/bin/python2.7

Do note that there is nothing special about the name xenials. It's just  
a group I have defined in my inventory.

// Andreas

---

<div class="post-metadata">

**Author:** ![Peter\_Loron](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@Peter\_Loron](https://forum.ansible.com/u/Peter_Loron)\
**Post date:** [April 25, 2016, 5:33am UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252/3 "2016-04-25T05:33:50Z")

</div>

You can’t see it, but this is me banging my face into my desk. No support for Python 3? It’s been out how long?

Sigh. The principal reason I prefer to use Ansible over Chef is that I DON’T need to install anything on the client to make it go. This release of Ubuntu is going to be everywhere shortly. Maybe Canonical dropping Python 2 from the distro is the wrong thing to have done, but that die is cast…

---

<div class="post-metadata">

**Author:** ![Aapo\_Rista](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@Aapo\_Rista](https://forum.ansible.com/u/Aapo_Rista)\
**Post date:** [April 26, 2016, 4:19pm UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252/4 "2016-04-26T16:19:42Z")

</div>

I just want to confirm, that I got this working with Andreas’ instructions.

I just added these lines to my inventory file:

**[xenials] # Ubuntu 16.04 hosts without python2**  
**[myhost.example.org](http://myhost.example.org) ansible\_user=root**

**[xenials:vars]**  
**ansible\_python\_interpreter=/usr/bin/python2.7**

[server] # This already existed  
[myhost.example.org](http://myhost.example.org) ansible\_user=root

And these to my init.yml:

**- hosts: xenials**  
**gather\_facts: False**  
**tasks:**  
**- name: apt-get update**  
**raw: apt-get update -qq**  
**- name: Install python 2.7**  
**raw: apt-get install -qq python2.7**

Thanks Andreas!

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [April 26, 2016, 11:59pm UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252/5 "2016-04-26T23:59:27Z")

</div>

It’s coming, but there are a _lot_ of hoops to jump to make Py3 work while continuing to support back to Python 2.4 in modules (eg, RHEL5 support). It sounds like RHEL will likely do the same for RHEL8, and others too… Life would be much easier if we could just say, Py2.6/2.7/3.4+, but we’d have at least as much hollering from the crowd that’s still supporting RHEL5 and other “legacy” distros.

We’re definitely not ignoring the problem- a lot of groundwork was laid for Py3 compat in 2.1 (on both control and module side), and it’ll likely be a major theme of 2.2.

-Matt

---

<div class="post-metadata">

**Author:** ![codfather](https://avatars.discourse-cdn.com/v4/letter/c/bcef8e/32.png) [@codfather](https://forum.ansible.com/u/codfather)\
**Post date:** [May 11, 2016, 10:28am UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252/6 "2016-05-11T10:28:37Z")

</div>

Andreas, when I implemented this, I had to put a line in the section to use sudo for the installation, which makes sense, just wondering if you had achieved that another way , just curious.

I initially did these manually for testing, but this is obviously a much better solution for large scale roll outs, without having to update the AMI first.

Thanks for the post.

Cheers

Nick

---

<div class="post-metadata">

**Author:** ![Andreas\_Olsson](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Andreas\_Olsson](https://forum.ansible.com/u/Andreas_Olsson)\
**Post date:** [May 16, 2016, 11:04am UTC](https://forum.ansible.com/t/python-not-found-in-ubuntu-16-04-server/21252/7 "2016-05-16T11:04:37Z")

</div>

> Andreas, when I implemented this, I had to put a line in the section  
> to use sudo for the installation, which makes sense, just wondering  
> if you had achieved that another way , just curious.

Yepp, I have the following in my ansible.cfg

[privilege\_escalation]  
become = True

(Where sudo is the default become\_method)

> Thanks for the post.

Glad it helped!

// Andreas
