Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible command from inside virtualenv?

This seems like it should be really simple:

tasks: - name: install python packages   pip: name=${item} virtualenv=~/buildbot-env   with_items: [ buildbot ] - name: create buildbot master   command: buildbot create-master ~/buildbot creates=~/buildbot/buildbot.tac 

However, the command will not succeed unless the virtualenv's activate script is sourced first, and there doesn't seem to be provision to do that in the Ansible command module.

I've experimented with sourcing the activate script in various of .profile, .bashrc, .bash_login, etc, with no luck. Alternatively, there's the shell command, but it seems like kind of an awkward hack:

- name: create buildbot master   shell: source ~/buildbot-env/bin/activate && \          buildbot create-master ~/buildbot \          creates=~/buildbot/buildbot.tac executable=/bin/bash 

Is there a better way?

like image 401
mikepurvis Avatar asked Nov 18 '13 04:11

mikepurvis


People also ask

Where is Ansible CFG in Virtualenv?

ansible. cfg (in the home directory) /etc/ansible/ansible. cfg.

What is Ansible Virtualenv?

Ansible Tower 3.0 and later uses virtualenv. Virtualenv creates isolated Python environments to avoid problems caused by conflicting dependencies and differing versions. Virtualenv works by simply creating a folder which contains all of the necessary executables and dependencies for a specific version of Python.


1 Answers

The better way is to use the full path to installed script - it will run in its virtualenv automatically:

tasks: - name: install python packages   pip: name={{ item }} virtualenv={{ venv }}   with_items: [ buildbot ] - name: create buildbot master   command: "{{ venv }}/bin/buildbot create-master ~/buildbot             creates=~/buildbot/buildbot.tac" 
like image 157
anatoly techtonik Avatar answered Sep 21 '22 08:09

anatoly techtonik