Is this answer still considered the best way to run a command that requires a virtualenv to run?
http://stackoverflow.com/questions/20040141/ansible-command-from-inside-virtualenv?rq=1 pasting the answer for posterity, --- # Build virtualenv - hosts: all vars: PROJECT_HOME: "/tmp/my_test_home" ansible_python_interpreter: "/usr/local/bin/python" tasks: - name: "Create virtualenv" shell: virtualenv "{{ PROJECT_HOME }}/venv" creates="{{ PROJECT_HOME }}/venv/bin/activate" - name: "Copy virtualenv wrapper file" synchronize: src=pyvenv dest="{{ PROJECT_HOME }}/venv/bin/pyvenv" # Use virtualenv - hosts: all vars: PROJECT_HOME: "/tmp/my_test_home" ansible_python_interpreter: "/tmp/my_test_home/venv/bin/pyvenv" tasks: - name: "Guard code, so we are more certain we are in a virtualenv" shell: echo $VIRTUAL_ENV register: command_result failed_when: command_result.stdout == "" pyenv wrapper file: #!/bin/bash source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/activate" python $@ -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/605f3cdc-3337-4259-883f-f7c2ddbfc974%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
