ansible rax not picking up virtualenv python executable

42 views
Skip to first unread message

the af

unread,
Dec 30, 2015, 6:07:54 PM12/30/15
to Ansible Project
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
```
  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


the af

unread,
Dec 31, 2015, 5:36:35 AM12/31/15
to Ansible Project
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

the af

unread,
Jan 5, 2016, 4:44:25 AM1/5/16
to Ansible Project
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



On Wednesday, 30 December 2015 23:07:54 UTC, the af wrote:
Reply all
Reply to author
Forward
0 new messages