# ansible rax not picking up virtualenv python executable

**URL:** <https://forum.ansible.com/t/ansible-rax-not-picking-up-virtualenv-python-executable/20103>\
**Category:** Ansible Project\
**Created:** [December 30, 2015, 11:07pm UTC](https://forum.ansible.com/t/ansible-rax-not-picking-up-virtualenv-python-executable/20103 "2015-12-30T23:07:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chinedu\_uzoka](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@chinedu\_uzoka](https://forum.ansible.com/u/chinedu_uzoka)\
**Post date:** [December 30, 2015, 11:07pm UTC](https://forum.ansible.com/t/ansible-rax-not-picking-up-virtualenv-python-executable/20103/1 "2015-12-30T23:07:53Z")

</div>

Hi

I have a site spectific module for deploying cloud objects on Rackspaces platform. The objects created are the following: networks, vyatta and cloud servers. I use rax.py that i have symlinked to 4 inventory directories. The purpose of the symylinking is to allow each environment to be built independently. The virtual environment were created using virtualenv --system-site-packages. Ansible has been installed system wide on kubuntu 15.10 and the install of pyrax within virtual environment

Oddly when executing ansible-playbook rather than the execution using virtualenvs python executable it defaults to using /usr/bin/python and thats because the rax modules use #!/usr/bin/python as opposed to #!/usr/bin/env python. The latter works.

The ansible\_python\_interpreter does not work and the following code

```auto
tasks:
- debug: msg="{{ ansible_python_interpreter }}"

```

outputs virtualenvs python executable

I was successfully using this without any hacks and it worked - now it does not work. I cant quite get my head around this. I have used both global ansible and virtualenvs ansible but non work.

Any help will mbe much appreciated

Kubuntu 15.10  
Ansible 1.9.4.1

---

<div class="post-metadata">

**Author:** ![chinedu\_uzoka](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@chinedu\_uzoka](https://forum.ansible.com/u/chinedu_uzoka)\
**Post date:** [December 31, 2015, 10:36am UTC](https://forum.ansible.com/t/ansible-rax-not-picking-up-virtualenv-python-executable/20103/2 "2015-12-31T10:36:35Z")

</div>

This would mean that using Virtualenv and installing ansible third party python libraries breaks Ansible  
It appears that this code here ansible\_root/runner/shell\_plugins/sh.py

def build\_module\_command(self, env\_string, shebang, cmd, rm\_tmp=None):  
cmd\_parts = [env\_string.strip(), shebang.replace(“#!”, “”).strip(), cmd] \<------- this here is causing /usr/bin/python being used instead of ansible\_python\_interpreter  
new\_cmd = " ".join(cmd\_parts)  
if rm\_tmp:  
new\_cmd = ‘%s; rm -rf %s \>/dev/null 2\>&1’ % (new\_cmd, rm\_tmp)  
return new\_cmd

---

<div class="post-metadata">

**Author:** ![chinedu\_uzoka](https://avatars.discourse-cdn.com/v4/letter/c/839c29/32.png) [@chinedu\_uzoka](https://forum.ansible.com/u/chinedu_uzoka)\
**Post date:** [January 5, 2016, 9:44am UTC](https://forum.ansible.com/t/ansible-rax-not-picking-up-virtualenv-python-executable/20103/3 "2016-01-05T09:44:25Z")

</div>

appears that the yaml i used to create a cloud init definition was using a string block where i incorrectly wrote the following

…  
user\_data: |+  
#cloud-config  
groups:

- name: tech\_admin  
users:
- default
- name: as\_admin  
gecos: XXXXX Admin Server Account  
primary-group: xx\_admin  
groups: tech\_admin  
lock-passwd: true  
passwd: {{ lookup(‘file’, {{ playbook\_dir }}/files/rackspace\_cloud/rackspace\_admin.pub }}  
ssh-authorized-keys:
- {{ rs\_ssh\_admin\_key }}  
sudo:
- ALL=(ALL) NOPASSWD:ALL  
…

The error thru me off as it was a red herring - but the block above was incorrect
